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.



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

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.



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

def index
  @index
end

#last_checkinObject (readonly)

Returns the value of attribute last_checkin.



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

def last_checkin
  @last_checkin
end

#last_statusObject (readonly)

Returns the value of attribute last_status.



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

def last_status
  @last_status
end

#phaseObject (readonly)

Returns the value of attribute phase.



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

def phase
  @phase
end

#pidObject (readonly)

Returns the value of attribute pid.



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

def pid
  @pid
end

#signalObject (readonly)

Returns the value of attribute signal.



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

def signal
  @signal
end

Instance Method Details

#boot!Object



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

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

#booted?Boolean

Returns:

  • (Boolean)


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

def booted?
  @stage == :booted
end

#dead!Object



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

def dead!
  @dead = true
end

#dead?Boolean

Returns:

  • (Boolean)


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

def dead?
  @dead
end

#hupObject



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

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

#killObject



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

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

#ping!(status) ⇒ Object



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

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

#ping_timeout?(which) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#termObject



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

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