Class: Preforker::Worker
- Inherits:
-
Object
- Object
- Preforker::Worker
- Defined in:
- lib/preforker/worker.rb
Defined Under Namespace
Classes: WorkerAPI
Instance Attribute Summary collapse
-
#pid ⇒ Object
Returns the value of attribute pid.
-
#tmp ⇒ Object
readonly
Returns the value of attribute tmp.
Instance Method Summary collapse
- #handle_signals ⇒ Object
- #init ⇒ Object
- #init_self_pipe! ⇒ Object
-
#initialize(worker_block, master) ⇒ Worker
constructor
A new instance of Worker.
- #log(message) ⇒ Object
- #proc_message(message) ⇒ Object
- #work ⇒ Object
Constructor Details
Instance Attribute Details
#pid ⇒ Object
Returns the value of attribute pid.
35 36 37 |
# File 'lib/preforker/worker.rb', line 35 def pid @pid end |
#tmp ⇒ Object (readonly)
Returns the value of attribute tmp.
34 35 36 |
# File 'lib/preforker/worker.rb', line 34 def tmp @tmp end |
Instance Method Details
#handle_signals ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/preforker/worker.rb', line 62 def handle_signals [:TERM, :INT].each do |sig| trap(sig) { exit!(0) } end [:EXIT, :QUIT].each do |sig| trap(sig){ @master_api.kill } end #what usr1 does trap(:USR1) { @read_pipe.close rescue nil } trap(:CHLD, 'DEFAULT') end |
#init ⇒ Object
55 56 57 58 59 60 |
# File 'lib/preforker/worker.rb', line 55 def init init_self_pipe! handle_signals tmp.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC) @master_api = WorkerAPI.new(self, @master) end |
#init_self_pipe! ⇒ Object
43 44 45 46 |
# File 'lib/preforker/worker.rb', line 43 def init_self_pipe! @read_pipe, @write_pipe = IO.pipe [@read_pipe, @write_pipe].each { |io| io.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC) } end |
#log(message) ⇒ Object
81 82 83 84 |
# File 'lib/preforker/worker.rb', line 81 def log() = () @master.logger.info end |
#proc_message(message) ⇒ Object
76 77 78 79 |
# File 'lib/preforker/worker.rb', line 76 def () = ["#{@master.app_name} Child #{$$}", ].join(": ") $0 = end |
#work ⇒ Object
48 49 50 51 52 53 |
# File 'lib/preforker/worker.rb', line 48 def work log "Created" init @worker_block.call(@master_api) if @master_api.wants_me_alive? end |