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.



46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/puma/cluster.rb', line 46

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.



59
60
61
# File 'lib/puma/cluster.rb', line 59

def index
  @index
end

#last_checkinObject (readonly)

Returns the value of attribute last_checkin.



59
60
61
# File 'lib/puma/cluster.rb', line 59

def last_checkin
  @last_checkin
end

#last_statusObject (readonly)

Returns the value of attribute last_status.



59
60
61
# File 'lib/puma/cluster.rb', line 59

def last_status
  @last_status
end

#phaseObject (readonly)

Returns the value of attribute phase.



59
60
61
# File 'lib/puma/cluster.rb', line 59

def phase
  @phase
end

#pidObject (readonly)

Returns the value of attribute pid.



59
60
61
# File 'lib/puma/cluster.rb', line 59

def pid
  @pid
end

#signalObject (readonly)

Returns the value of attribute signal.



59
60
61
# File 'lib/puma/cluster.rb', line 59

def signal
  @signal
end

Instance Method Details

#boot!Object



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

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

#booted?Boolean

Returns:

  • (Boolean)


61
62
63
# File 'lib/puma/cluster.rb', line 61

def booted?
  @stage == :booted
end

#dead!Object



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

def dead!
  @dead = true
end

#dead?Boolean

Returns:

  • (Boolean)


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

def dead?
  @dead
end

#hupObject



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

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

#killObject



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

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

#ping!(status) ⇒ Object



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

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

#ping_timeout?(which) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#termObject



87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/puma/cluster.rb', line 87

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