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
62 63 64 65 66 67 |
# File 'lib/perfectqueue/multiprocess/child_process.rb', line 62 def child_heartbeat @wpipe.write HEARTBEAT_PACKET rescue @log.error "Parent process unexpectedly died: #{$!}" force_stop end |
#force_stop ⇒ Object
override
70 71 72 73 74 |
# File 'lib/perfectqueue/multiprocess/child_process.rb', line 70 def force_stop super Process.kill(:KILL, Process.pid) exit! 137 end |
#join ⇒ Object
override
47 48 49 |
# File 'lib/perfectqueue/multiprocess/child_process.rb', line 47 def join # do nothing end |
#keepalive ⇒ Object
override
52 53 54 |
# File 'lib/perfectqueue/multiprocess/child_process.rb', line 52 def keepalive # do nothing end |
#logrotated ⇒ Object
override
57 58 59 |
# File 'lib/perfectqueue/multiprocess/child_process.rb', line 57 def logrotated @log.reopen! end |
#process(task) ⇒ Object
override
85 86 87 88 89 90 91 92 93 |
# File 'lib/perfectqueue/multiprocess/child_process.rb', line 85 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
79 80 81 82 |
# File 'lib/perfectqueue/multiprocess/child_process.rb', line 79 def restart(immediate, config) @max_request_per_child = config[:max_request_per_child] || nil super end |
#run ⇒ Object
override
36 37 38 |
# File 'lib/perfectqueue/multiprocess/child_process.rb', line 36 def run super end |
#stop(immediate) ⇒ Object
override
41 42 43 44 |
# File 'lib/perfectqueue/multiprocess/child_process.rb', line 41 def stop(immediate) @log.info "Exiting processor id=#{@processor_id} pid=#{Process.pid}" super end |