Class: Puma::Cluster::WorkerHandle
- Inherits:
-
Object
- Object
- Puma::Cluster::WorkerHandle
- Defined in:
- lib/puma/cluster/worker_handle.rb
Overview
This class represents a worker process from the perspective of the puma master process. It contains information about the process and its health and it exposes methods to control the process via IPC. It does not include the actual logic executed by the worker process itself. For that, see Puma::Cluster::Worker.
Instance Attribute Summary collapse
-
#index ⇒ Object
readonly
Returns the value of attribute index.
-
#last_checkin ⇒ Object
readonly
Returns the value of attribute last_checkin.
-
#last_status ⇒ Object
readonly
Returns the value of attribute last_status.
-
#phase ⇒ Object
Returns the value of attribute phase.
-
#pid ⇒ Object
Returns the value of attribute pid.
-
#signal ⇒ Object
readonly
Returns the value of attribute signal.
-
#started_at ⇒ Object
readonly
Returns the value of attribute started_at.
Instance Method Summary collapse
- #boot! ⇒ Object
- #booted? ⇒ Boolean
- #hup ⇒ Object
-
#initialize(idx, pid, phase, options) ⇒ WorkerHandle
constructor
A new instance of WorkerHandle.
- #kill ⇒ Object
- #ping!(status) ⇒ Object
- #ping_timeout ⇒ Object
- #term ⇒ Object
- #term! ⇒ Object
- #term? ⇒ Boolean
- #uptime ⇒ Object
Constructor Details
#initialize(idx, pid, phase, options) ⇒ WorkerHandle
Returns a new instance of WorkerHandle.
11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/puma/cluster/worker_handle.rb', line 11 def initialize(idx, pid, phase, ) @index = idx @pid = pid @phase = phase @stage = :started @signal = "TERM" @options = @first_term_sent = nil @started_at = Time.now @last_checkin = Time.now @last_status = {} @term = false end |
Instance Attribute Details
#index ⇒ Object (readonly)
Returns the value of attribute index.
25 26 27 |
# File 'lib/puma/cluster/worker_handle.rb', line 25 def index @index end |
#last_checkin ⇒ Object (readonly)
Returns the value of attribute last_checkin.
25 26 27 |
# File 'lib/puma/cluster/worker_handle.rb', line 25 def last_checkin @last_checkin end |
#last_status ⇒ Object (readonly)
Returns the value of attribute last_status.
25 26 27 |
# File 'lib/puma/cluster/worker_handle.rb', line 25 def last_status @last_status end |
#phase ⇒ Object
Returns the value of attribute phase.
25 26 27 |
# File 'lib/puma/cluster/worker_handle.rb', line 25 def phase @phase end |
#pid ⇒ Object
Returns the value of attribute pid.
25 26 27 |
# File 'lib/puma/cluster/worker_handle.rb', line 25 def pid @pid end |
#signal ⇒ Object (readonly)
Returns the value of attribute signal.
25 26 27 |
# File 'lib/puma/cluster/worker_handle.rb', line 25 def signal @signal end |
#started_at ⇒ Object (readonly)
Returns the value of attribute started_at.
25 26 27 |
# File 'lib/puma/cluster/worker_handle.rb', line 25 def started_at @started_at end |
Instance Method Details
#boot! ⇒ Object
38 39 40 41 |
# File 'lib/puma/cluster/worker_handle.rb', line 38 def boot! @last_checkin = Time.now @stage = :booted end |
#booted? ⇒ Boolean
30 31 32 |
# File 'lib/puma/cluster/worker_handle.rb', line 30 def booted? @stage == :booted end |
#hup ⇒ Object
88 89 90 91 |
# File 'lib/puma/cluster/worker_handle.rb', line 88 def hup Process.kill "HUP", @pid rescue Errno::ESRCH end |
#kill ⇒ Object
83 84 85 86 |
# File 'lib/puma/cluster/worker_handle.rb', line 83 def kill @signal = 'KILL' term end |
#ping!(status) ⇒ Object
51 52 53 54 55 56 57 58 |
# File 'lib/puma/cluster/worker_handle.rb', line 51 def ping!(status) @last_checkin = Time.now captures = status.match(/{ "backlog":(?<backlog>\d*), "running":(?<running>\d*), "pool_capacity":(?<pool_capacity>\d*), "max_threads": (?<max_threads>\d*), "requests_count": (?<requests_count>\d*) }/) @last_status = captures.names.inject({}) do |hash, key| hash[key.to_sym] = captures[key].to_i hash end end |
#ping_timeout ⇒ Object
62 63 64 65 66 67 68 |
# File 'lib/puma/cluster/worker_handle.rb', line 62 def ping_timeout @last_checkin + (booted? ? @options[:worker_timeout] : @options[:worker_boot_timeout] ) end |
#term ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/puma/cluster/worker_handle.rb', line 70 def term begin if @first_term_sent && (Time.now - @first_term_sent) > @options[:worker_shutdown_timeout] @signal = "KILL" else @term ||= true @first_term_sent ||= Time.now end Process.kill @signal, @pid if @pid rescue Errno::ESRCH end end |
#term! ⇒ Object
43 44 45 |
# File 'lib/puma/cluster/worker_handle.rb', line 43 def term! @term = true end |
#term? ⇒ Boolean
47 48 49 |
# File 'lib/puma/cluster/worker_handle.rb', line 47 def term? @term end |
#uptime ⇒ Object
34 35 36 |
# File 'lib/puma/cluster/worker_handle.rb', line 34 def uptime Time.now - started_at end |