Class: Puma::Cluster::Worker

Inherits:
Object
  • Object
show all
Defined in:
lib/puma/cluster.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Worker.


65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/puma/cluster.rb', line 65

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


79
80
81
# File 'lib/puma/cluster.rb', line 79

def index
  @index
end

#last_checkinObject (readonly)

Returns the value of attribute last_checkin


79
80
81
# File 'lib/puma/cluster.rb', line 79

def last_checkin
  @last_checkin
end

#last_statusObject (readonly)

Returns the value of attribute last_status


79
80
81
# File 'lib/puma/cluster.rb', line 79

def last_status
  @last_status
end

#phaseObject

Returns the value of attribute phase


79
80
81
# File 'lib/puma/cluster.rb', line 79

def phase
  @phase
end

#pidObject

Returns the value of attribute pid


79
80
81
# File 'lib/puma/cluster.rb', line 79

def pid
  @pid
end

#signalObject (readonly)

Returns the value of attribute signal


79
80
81
# File 'lib/puma/cluster.rb', line 79

def signal
  @signal
end

#started_atObject (readonly)

Returns the value of attribute started_at


79
80
81
# File 'lib/puma/cluster.rb', line 79

def started_at
  @started_at
end

Instance Method Details

#boot!Object


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

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

#booted?Boolean

Returns:

  • (Boolean)

82
83
84
# File 'lib/puma/cluster.rb', line 82

def booted?
  @stage == :booted
end

#hupObject


127
128
129
130
# File 'lib/puma/cluster.rb', line 127

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

#killObject


122
123
124
125
# File 'lib/puma/cluster.rb', line 122

def kill
  @signal = 'KILL'
  term
end

#ping!(status) ⇒ Object


95
96
97
98
99
# File 'lib/puma/cluster.rb', line 95

def ping!(status)
  @last_checkin = Time.now
  require 'json'
  @last_status = JSON.parse(status, symbolize_names: true)
end

#ping_timeoutObject


101
102
103
104
105
106
107
# File 'lib/puma/cluster.rb', line 101

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

#termObject


109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/puma/cluster.rb', line 109

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?Boolean

Returns:

  • (Boolean)

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

def term?
  @term
end