class Puma::Cluster::WorkerHandle

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.

Attributes

index[R]
last_checkin[R]
last_status[R]
phase[RW]
pid[RW]
signal[R]
started_at[R]

Public Class Methods

new(idx, pid, phase, options) click to toggle source
# File lib/puma/cluster/worker_handle.rb, line 10
def initialize(idx, pid, phase, options)
  @index = idx
  @pid = pid
  @phase = phase
  @stage = :started
  @signal = "TERM"
  @options = options
  @first_term_sent = nil
  @started_at = Time.now
  @last_checkin = Time.now
  @last_status = {}
  @term = false
end

Public Instance Methods

boot!() click to toggle source
# File lib/puma/cluster/worker_handle.rb, line 37
def boot!
  @last_checkin = Time.now
  @stage = :booted
end
booted?() click to toggle source
# File lib/puma/cluster/worker_handle.rb, line 29
def booted?
  @stage == :booted
end
hup() click to toggle source
# File lib/puma/cluster/worker_handle.rb, line 87
def hup
  Process.kill "HUP", @pid
rescue Errno::ESRCH
end
kill() click to toggle source
# File lib/puma/cluster/worker_handle.rb, line 82
def kill
  @signal = 'KILL'
  term
end
ping!(status) click to toggle source
# File lib/puma/cluster/worker_handle.rb, line 50
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() click to toggle source

@see Puma::Cluster#check_workers @version 5.0.0

# File lib/puma/cluster/worker_handle.rb, line 61
def ping_timeout
  @last_checkin +
    (booted? ?
      @options[:worker_timeout] :
      @options[:worker_boot_timeout]
    )
end
term() click to toggle source
# File lib/puma/cluster/worker_handle.rb, line 69
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!() click to toggle source
# File lib/puma/cluster/worker_handle.rb, line 42
def term!
  @term = true
end
term?() click to toggle source
# File lib/puma/cluster/worker_handle.rb, line 46
def term?
  @term
end
uptime() click to toggle source
# File lib/puma/cluster/worker_handle.rb, line 33
def uptime
  Time.now - started_at
end