Class: ServerEngine::MultiProcessServer::WorkerMonitor

Inherits:
Object
  • Object
show all
Defined in:
lib/serverengine/multi_process_server.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(worker, wid, pmon, reload_signal = Signals::RELOAD, unrecoverable_exit_codes: []) ⇒ WorkerMonitor

Returns a new instance of WorkerMonitor.



100
101
102
103
104
105
106
107
108
109
# File 'lib/serverengine/multi_process_server.rb', line 100

def initialize(worker, wid, pmon, reload_signal = Signals::RELOAD, unrecoverable_exit_codes: [])
  @worker = worker
  @wid = wid
  @pmon = pmon
  @reload_signal = reload_signal
  @unrecoverable_exit_codes = unrecoverable_exit_codes
  @unrecoverable_exit = false
  @exitstatus = nil
  @restart_at = nil
end

Instance Attribute Details

#exitstatusObject (readonly)

Returns the value of attribute exitstatus.



111
112
113
# File 'lib/serverengine/multi_process_server.rb', line 111

def exitstatus
  @exitstatus
end

#restart_atObject

Returns the value of attribute restart_at.



112
113
114
# File 'lib/serverengine/multi_process_server.rb', line 112

def restart_at
  @restart_at
end

Instance Method Details

#alive?Boolean

Returns:

  • (Boolean)


143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# File 'lib/serverengine/multi_process_server.rb', line 143

def alive?
  return false unless @pmon

  if stat = @pmon.try_join
    if @stop
      @worker.logger.info "Worker #{@wid} finished with #{ServerEngine.format_join_status(stat)}"
    else
      if stat.is_a?(Process::Status) && stat.success?
        @worker.logger.info "Worker #{@wid} exited with #{ServerEngine.format_join_status(stat)}"
      else
        @worker.logger.error "Worker #{@wid} exited unexpectedly with #{ServerEngine.format_join_status(stat)}"
      end
    end
    if stat.is_a?(Process::Status) && stat.exited? && @unrecoverable_exit_codes.include?(stat.exitstatus)
      @unrecoverable_exit = true
      @exitstatus = stat.exitstatus
    end
    @pmon = nil
    return false
  else
    return true
  end
end

#joinObject



138
139
140
141
# File 'lib/serverengine/multi_process_server.rb', line 138

def join
  @pmon.join if @pmon
  nil
end

#recoverable?Boolean

Returns:

  • (Boolean)


167
168
169
# File 'lib/serverengine/multi_process_server.rb', line 167

def recoverable?
  !@unrecoverable_exit
end

#send_command(command) ⇒ Object



134
135
136
# File 'lib/serverengine/multi_process_server.rb', line 134

def send_command(command)
  @pmon.send_command(command) if @pmon
end

#send_reloadObject



124
125
126
127
128
129
130
131
132
# File 'lib/serverengine/multi_process_server.rb', line 124

def send_reload
  return nil unless @pmon
  if @pmon.command_sender_pipe
    send_command("RELOAD\n")
  else
    @pmon.send_signal(@reload_signal)
  end
  nil
end

#send_stop(stop_graceful) ⇒ Object



114
115
116
117
118
119
120
121
122
# File 'lib/serverengine/multi_process_server.rb', line 114

def send_stop(stop_graceful)
  @stop = true
  if stop_graceful
    @pmon.start_graceful_stop! if @pmon
  else
    @pmon.start_immediate_stop! if @pmon
  end
  nil
end