Class: Puma::Cluster::WorkerHandle
Do not use. This class is for internal use only.
Relationships & Source Files | |
Inherits: | Object |
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 Worker
.
Constant Summary
-
WORKER_MAX_KEYS =
array of stat ‘max’ keys
[:backlog_max, :reactor_max]
Class Method Summary
- .new(idx, pid, phase, options) ⇒ WorkerHandle constructor
Instance Attribute Summary
- #booted? ⇒ Boolean readonly
- #index readonly
- #last_checkin readonly
- #last_status readonly
- #phase rw
- #phase=(value) rw
- #pid rw
- #pid=(value) rw
- #signal readonly
- #started_at readonly
- #term? ⇒ Boolean readonly
Instance Method Summary
- #boot!
- #hup
- #kill
- #ping!(status)
- #ping_timeout
-
#reset_max
Resets max values to zero.
- #term readonly
- #term!
- #uptime
Constructor Details
.new(idx, pid, phase, options) ⇒ WorkerHandle
# File 'lib/puma/cluster/worker_handle.rb', line 16
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 @worker_max = Array.new WORKER_MAX_KEYS.length, 0 end
Instance Attribute Details
#booted? ⇒ Boolean
(readonly)
[ GitHub ]
# File 'lib/puma/cluster/worker_handle.rb', line 36
def booted? @stage == :booted end
#index (readonly)
[ GitHub ]# File 'lib/puma/cluster/worker_handle.rb', line 31
attr_reader :index, :pid, :phase, :signal, :last_checkin, :last_status, :started_at
#last_checkin (readonly)
[ GitHub ]# File 'lib/puma/cluster/worker_handle.rb', line 31
attr_reader :index, :pid, :phase, :signal, :last_checkin, :last_status, :started_at
#last_status (readonly)
[ GitHub ]# File 'lib/puma/cluster/worker_handle.rb', line 31
attr_reader :index, :pid, :phase, :signal, :last_checkin, :last_status, :started_at
#phase (rw)
[ GitHub ]# File 'lib/puma/cluster/worker_handle.rb', line 31
attr_reader :index, :pid, :phase, :signal, :last_checkin, :last_status, :started_at
#phase=(value) (rw)
#pid (rw)
[ GitHub ]# File 'lib/puma/cluster/worker_handle.rb', line 31
attr_reader :index, :pid, :phase, :signal, :last_checkin, :last_status, :started_at
#pid=(value) (rw)
#signal (readonly)
[ GitHub ]# File 'lib/puma/cluster/worker_handle.rb', line 31
attr_reader :index, :pid, :phase, :signal, :last_checkin, :last_status, :started_at
#started_at (readonly)
[ GitHub ]# File 'lib/puma/cluster/worker_handle.rb', line 31
attr_reader :index, :pid, :phase, :signal, :last_checkin, :last_status, :started_at
#term? ⇒ Boolean
(readonly)
[ GitHub ]
# File 'lib/puma/cluster/worker_handle.rb', line 53
def term? @term end
Instance Method Details
#boot!
[ GitHub ]# File 'lib/puma/cluster/worker_handle.rb', line 44
def boot! @last_checkin = Time.now @stage = :booted end
#hup
[ GitHub ]# File 'lib/puma/cluster/worker_handle.rb', line 120
def hup Process.kill "HUP", @pid rescue Errno::ESRCH end
#kill
[ GitHub ]# File 'lib/puma/cluster/worker_handle.rb', line 115
def kill @signal = 'KILL' term end
#ping!(status)
[ GitHub ]# File 'lib/puma/cluster/worker_handle.rb', line 57
def ping!(status) hsh = {} k, v = nil, nil # @todo remove each once Ruby 2.5 is no longer supported status.tr('}{"', '').strip.split(", ").each do |kv| cntr = 0 kv.split(':').each do |t| if cntr == 0 k = t cntr = 1 else v = t end end hsh[k.to_sym] = v.to_i end # check stat max values, we can't signal workers to reset the max values, # so we do so here WORKER_MAX_KEYS.each_with_index do |key, idx| if hsh[key] < @worker_max[idx] hsh[key] = @worker_max[idx] else @worker_max[idx] = hsh[key] end end @last_checkin = Time.now @last_status = hsh end
#ping_timeout
# File 'lib/puma/cluster/worker_handle.rb', line 94
def ping_timeout @last_checkin + (booted? ? @options[:worker_timeout] : @options[:worker_boot_timeout] ) end
#reset_max
Resets max values to zero. Called whenever Puma::Cluster#stats is called
# File 'lib/puma/cluster/worker_handle.rb', line 88
def reset_max WORKER_MAX_KEYS.length.times { |idx| @worker_max[idx] = 0 } end
#term (readonly)
[ GitHub ]# File 'lib/puma/cluster/worker_handle.rb', line 102
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!
[ GitHub ]# File 'lib/puma/cluster/worker_handle.rb', line 49
def term! @term = true end
#uptime
[ GitHub ]# File 'lib/puma/cluster/worker_handle.rb', line 40
def uptime Time.now - started_at end