Class: Puma::Cluster::WorkerHandle

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(idx, pid, phase, options) ⇒ WorkerHandle

:nodoc:



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/puma/cluster/worker_handle.rb', line 14

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

Instance Attribute Details

#indexObject (readonly)

Returns the value of attribute index.



28
29
30
# File 'lib/puma/cluster/worker_handle.rb', line 28

def index
  @index
end

#last_checkinObject (readonly)

Returns the value of attribute last_checkin.



28
29
30
# File 'lib/puma/cluster/worker_handle.rb', line 28

def last_checkin
  @last_checkin
end

#last_statusObject (readonly)

Returns the value of attribute last_status.



28
29
30
# File 'lib/puma/cluster/worker_handle.rb', line 28

def last_status
  @last_status
end

#phaseObject

Returns the value of attribute phase.



28
29
30
# File 'lib/puma/cluster/worker_handle.rb', line 28

def phase
  @phase
end

#pidObject

Returns the value of attribute pid.



28
29
30
# File 'lib/puma/cluster/worker_handle.rb', line 28

def pid
  @pid
end

#signalObject (readonly)

Returns the value of attribute signal.



28
29
30
# File 'lib/puma/cluster/worker_handle.rb', line 28

def signal
  @signal
end

#started_atObject (readonly)

Returns the value of attribute started_at.



28
29
30
# File 'lib/puma/cluster/worker_handle.rb', line 28

def started_at
  @started_at
end

Instance Method Details

#boot!Object



41
42
43
44
# File 'lib/puma/cluster/worker_handle.rb', line 41

def boot!
  @last_checkin = Time.now
  @stage = :booted
end

#booted?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/puma/cluster/worker_handle.rb', line 33

def booted?
  @stage == :booted
end

#hupObject



90
91
92
93
# File 'lib/puma/cluster/worker_handle.rb', line 90

def hup
  Process.kill "HUP", @pid
rescue Errno::ESRCH
end

#killObject



85
86
87
88
# File 'lib/puma/cluster/worker_handle.rb', line 85

def kill
  @signal = 'KILL'
  term
end

#ping!(status) ⇒ Object



57
58
59
60
# 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_timeoutObject

See Also:

Version:

  • 5.0.0



64
65
66
67
68
69
70
# File 'lib/puma/cluster/worker_handle.rb', line 64

def ping_timeout
  @last_checkin +
    (booted? ?
      @options[:worker_timeout] :
      @options[:worker_boot_timeout]
    )
end

#termObject



72
73
74
75
76
77
78
79
80
81
82
83
# 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!Object



46
47
48
# File 'lib/puma/cluster/worker_handle.rb', line 46

def term!
  @term = true
end

#term?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/puma/cluster/worker_handle.rb', line 50

def term?
  @term
end

#uptimeObject



37
38
39
# File 'lib/puma/cluster/worker_handle.rb', line 37

def uptime
  Time.now - started_at
end