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
-
STATUS_PATTERN =
private
# File 'lib/puma/cluster/worker_handle.rb', line 54/{ "backlog":(?<backlog>\d*), "running":(?<running>\d*), "pool_capacity":(?<pool_capacity>\d*), "max_threads":(?<max_threads>\d*), "requests_count":(?<requests_count>\d*) }/
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
- #term readonly
- #term!
- #uptime
Constructor Details
.new(idx, pid, phase, options) ⇒ WorkerHandle
Instance Attribute Details
#booted? ⇒ Boolean
(readonly)
[ GitHub ]
# File 'lib/puma/cluster/worker_handle.rb', line 33
def booted? @stage == :booted end
#index (readonly)
[ GitHub ]# File 'lib/puma/cluster/worker_handle.rb', line 28
attr_reader :index, :pid, :phase, :signal, :last_checkin, :last_status, :started_at
#last_checkin (readonly)
[ GitHub ]# File 'lib/puma/cluster/worker_handle.rb', line 28
attr_reader :index, :pid, :phase, :signal, :last_checkin, :last_status, :started_at
#last_status (readonly)
[ GitHub ]# File 'lib/puma/cluster/worker_handle.rb', line 28
attr_reader :index, :pid, :phase, :signal, :last_checkin, :last_status, :started_at
#phase (rw)
[ GitHub ]# File 'lib/puma/cluster/worker_handle.rb', line 28
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 28
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 28
attr_reader :index, :pid, :phase, :signal, :last_checkin, :last_status, :started_at
#started_at (readonly)
[ GitHub ]# File 'lib/puma/cluster/worker_handle.rb', line 28
attr_reader :index, :pid, :phase, :signal, :last_checkin, :last_status, :started_at
#term? ⇒ Boolean
(readonly)
[ GitHub ]
# File 'lib/puma/cluster/worker_handle.rb', line 50
def term? @term end
Instance Method Details
#boot!
[ GitHub ]# File 'lib/puma/cluster/worker_handle.rb', line 41
def boot! @last_checkin = Time.now @stage = :booted end
#hup
[ GitHub ]# File 'lib/puma/cluster/worker_handle.rb', line 90
def hup Process.kill "HUP", @pid rescue Errno::ESRCH end
#kill
[ GitHub ]# File 'lib/puma/cluster/worker_handle.rb', line 85
def kill @signal = 'KILL' term end
#ping!(status)
[ GitHub ]# File 'lib/puma/cluster/worker_handle.rb', line 57
def ping!(status) @last_checkin = Time.now @last_status = status.match(STATUS_PATTERN).named_captures.map { |c_name, c| [c_name.to_sym, c.to_i] }.to_h end
#ping_timeout
# File 'lib/puma/cluster/worker_handle.rb', line 64
def ping_timeout @last_checkin + (booted? ? @options[:worker_timeout] : @options[:worker_boot_timeout] ) end
#term (readonly)
[ GitHub ]# File 'lib/puma/cluster/worker_handle.rb', line 72
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 46
def term! @term = true end
#uptime
[ GitHub ]# File 'lib/puma/cluster/worker_handle.rb', line 37
def uptime Time.now - started_at end