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) ⇒ Worker

Returns a new instance of Worker.



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

def initialize(idx, pid, phase)
  @index = idx
  @pid = pid
  @phase = phase
  @stage = :started
  @signal = "TERM"
  @last_checkin = Time.now
end

Instance Attribute Details

#indexObject (readonly)

Returns the value of attribute index.



55
56
57
# File 'lib/puma/cluster.rb', line 55

def index
  @index
end

#last_checkinObject (readonly)

Returns the value of attribute last_checkin.



55
56
57
# File 'lib/puma/cluster.rb', line 55

def last_checkin
  @last_checkin
end

#phaseObject (readonly)

Returns the value of attribute phase.



55
56
57
# File 'lib/puma/cluster.rb', line 55

def phase
  @phase
end

#pidObject (readonly)

Returns the value of attribute pid.



55
56
57
# File 'lib/puma/cluster.rb', line 55

def pid
  @pid
end

#signalObject (readonly)

Returns the value of attribute signal.



55
56
57
# File 'lib/puma/cluster.rb', line 55

def signal
  @signal
end

Instance Method Details

#boot!Object



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

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

#booted?Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/puma/cluster.rb', line 57

def booted?
  @stage == :booted
end

#hupObject



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

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

#killObject



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

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

#ping!Object



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

def ping!
  @last_checkin = Time.now
end

#ping_timeout?(which) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#termObject



74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/puma/cluster.rb', line 74

def term
  begin
    if @first_term_sent && (Time.new - @first_term_sent) > 30
      @signal = "KILL"
    else
      @first_term_sent ||= Time.new
    end

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