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.


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

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


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

def index
  @index
end

#last_checkinObject (readonly)

Returns the value of attribute last_checkin


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

def last_checkin
  @last_checkin
end

#last_statusObject (readonly)

Returns the value of attribute last_status


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

def last_status
  @last_status
end

#phaseObject (readonly)

Returns the value of attribute phase


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

def phase
  @phase
end

#pidObject (readonly)

Returns the value of attribute pid


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

def pid
  @pid
end

#signalObject (readonly)

Returns the value of attribute signal


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

def signal
  @signal
end

#started_atObject (readonly)

Returns the value of attribute started_at


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

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


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

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

#killObject


117
118
119
120
# File 'lib/puma/cluster.rb', line 117

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

#ping!(status) ⇒ Object


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

def ping!(status)
  @last_checkin = Time.now
  @last_status = status
end

#ping_timeout?(which) ⇒ Boolean

Returns:

  • (Boolean)

100
101
102
# File 'lib/puma/cluster.rb', line 100

def ping_timeout?(which)
  Time.now - @last_checkin > which
end

#termObject


104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/puma/cluster.rb', line 104

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
  rescue Errno::ESRCH
  end
end

#term?Boolean

Returns:

  • (Boolean)

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

def term?
  @term
end