Class: PerfectQueue::Multiprocess::ChildProcess
- Inherits:
-
ThreadProcessor
- Object
- ThreadProcessor
- PerfectQueue::Multiprocess::ChildProcess
- Defined in:
- lib/perfectqueue/multiprocess/child_process.rb
Constant Summary collapse
- HEARTBEAT_PACKET =
[0].pack('C')
Class Method Summary collapse
Instance Method Summary collapse
-
#child_heartbeat ⇒ Object
override.
-
#force_stop ⇒ Object
override.
-
#initialize(runner, processor_id, config, wpipe) ⇒ ChildProcess
constructor
A new instance of ChildProcess.
-
#join ⇒ Object
override.
-
#keepalive ⇒ Object
override.
-
#logrotated ⇒ Object
override.
-
#process(task) ⇒ Object
override.
-
#restart(immediate, config) ⇒ Object
override.
-
#run ⇒ Object
override.
-
#stop(immediate) ⇒ Object
override.
Constructor Details
#initialize(runner, processor_id, config, wpipe) ⇒ ChildProcess
Returns a new instance of ChildProcess.
27 28 29 30 31 32 33 |
# File 'lib/perfectqueue/multiprocess/child_process.rb', line 27 def initialize(runner, processor_id, config, wpipe) @wpipe = wpipe @wpipe.sync = true @request_per_child = 0 super(runner, processor_id, config) @sig = install_signal_handlers end |
Class Method Details
.run(runner, processor_id, config, wpipe) ⇒ Object
23 24 25 |
# File 'lib/perfectqueue/multiprocess/child_process.rb', line 23 def self.run(runner, processor_id, config, wpipe) new(runner, processor_id, config, wpipe).run end |
Instance Method Details
#child_heartbeat ⇒ Object
override
63 64 65 66 67 68 |
# File 'lib/perfectqueue/multiprocess/child_process.rb', line 63 def child_heartbeat @wpipe.write HEARTBEAT_PACKET rescue @log.error "Parent process unexpectedly died: #{$!}" force_stop end |
#force_stop ⇒ Object
override
71 72 73 74 75 |
# File 'lib/perfectqueue/multiprocess/child_process.rb', line 71 def force_stop super Process.kill(:KILL, Process.pid) exit! 137 end |
#join ⇒ Object
override
48 49 50 |
# File 'lib/perfectqueue/multiprocess/child_process.rb', line 48 def join # do nothing end |
#keepalive ⇒ Object
override
53 54 55 |
# File 'lib/perfectqueue/multiprocess/child_process.rb', line 53 def keepalive # do nothing end |
#logrotated ⇒ Object
override
58 59 60 |
# File 'lib/perfectqueue/multiprocess/child_process.rb', line 58 def logrotated @log.reopen! end |
#process(task) ⇒ Object
override
86 87 88 89 90 91 92 93 94 |
# File 'lib/perfectqueue/multiprocess/child_process.rb', line 86 def process(task) super if @max_request_per_child @request_per_child += 1 if @request_per_child > @max_request_per_child stop(false) end end end |
#restart(immediate, config) ⇒ Object
override
80 81 82 83 |
# File 'lib/perfectqueue/multiprocess/child_process.rb', line 80 def restart(immediate, config) @max_request_per_child = config[:max_request_per_child] || nil super end |
#run ⇒ Object
override
36 37 38 39 |
# File 'lib/perfectqueue/multiprocess/child_process.rb', line 36 def run super @sig.stop end |
#stop(immediate) ⇒ Object
override
42 43 44 45 |
# File 'lib/perfectqueue/multiprocess/child_process.rb', line 42 def stop(immediate) @log.info "Exiting processor id=#{@processor_id} pid=#{Process.pid}" super end |