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.



51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/puma/cluster.rb', line 51

def initialize(idx, pid, phase, options)
  @index = idx
  @pid = pid
  @phase = phase
  @stage = :started
  @signal = "TERM"
  @options = options
  @first_term_sent = nil
  @last_checkin = Time.now
  @last_status = '{}'
  @dead = false
end

Instance Attribute Details

#indexObject (readonly)

Returns the value of attribute index.



64
65
66
# File 'lib/puma/cluster.rb', line 64

def index
  @index
end

#last_checkinObject (readonly)

Returns the value of attribute last_checkin.



64
65
66
# File 'lib/puma/cluster.rb', line 64

def last_checkin
  @last_checkin
end

#last_statusObject (readonly)

Returns the value of attribute last_status.



64
65
66
# File 'lib/puma/cluster.rb', line 64

def last_status
  @last_status
end

#phaseObject (readonly)

Returns the value of attribute phase.



64
65
66
# File 'lib/puma/cluster.rb', line 64

def phase
  @phase
end

#pidObject (readonly)

Returns the value of attribute pid.



64
65
66
# File 'lib/puma/cluster.rb', line 64

def pid
  @pid
end

#signalObject (readonly)

Returns the value of attribute signal.



64
65
66
# File 'lib/puma/cluster.rb', line 64

def signal
  @signal
end

Instance Method Details

#boot!Object



70
71
72
73
# File 'lib/puma/cluster.rb', line 70

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

#booted?Boolean

Returns:

  • (Boolean)


66
67
68
# File 'lib/puma/cluster.rb', line 66

def booted?
  @stage == :booted
end

#dead!Object



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

def dead!
  @dead = true
end

#dead?Boolean

Returns:

  • (Boolean)


75
76
77
# File 'lib/puma/cluster.rb', line 75

def dead?
  @dead
end

#hupObject



110
111
112
113
# File 'lib/puma/cluster.rb', line 110

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

#killObject



105
106
107
108
# File 'lib/puma/cluster.rb', line 105

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

#ping!(status) ⇒ Object



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

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

#ping_timeout?(which) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#termObject



92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/puma/cluster.rb', line 92

def term
  begin
    if @first_term_sent && (Time.now - @first_term_sent) > @options[:worker_shutdown_timeout]
      @signal = "KILL"
    else
      @first_term_sent ||= Time.now
    end

    Process.kill @signal, @pid
  rescue Errno::ESRCH
  end
end