Class: Waves::Worker
Overview
“Workers” are just dedicated processes. Managers, Servers, and Monitors are all examples of Workers. This class just encapsulates the common features across all Workers: daemonization, signal traps, console support, logging, only-ness, etc.
Direct Known Subclasses
Instance Attribute Summary
Attributes inherited from Runtime
Class Method Summary collapse
-
.instance ⇒ Object
make this the one-and-only.
- .run(options) ⇒ Object
Instance Method Summary collapse
- #daemonize ⇒ Object
- #restart ⇒ Object
- #set_traps ⇒ Object
-
#start ⇒ Object
returns the PID of the new process.
- #start_console ⇒ Object
- #start_debugger ⇒ Object
- #start_logger ⇒ Object
- #stop ⇒ Object
Methods inherited from Runtime
#config, #debug?, #initialize, #log, #mode, #reload, #synchronize, #synchronize?
Constructor Details
This class inherits a constructor from Waves::Runtime
Class Method Details
.instance ⇒ Object
make this the one-and-only
17 |
# File 'lib/runtime/worker.rb', line 17 def self.instance ; @instance ; end |
Instance Method Details
#daemonize ⇒ Object
41 42 43 44 45 46 |
# File 'lib/runtime/worker.rb', line 41 def daemonize pwd = Dir.pwd ; pid = fork ; return pid if pid ; Dir.chdir( pwd ) File.umask 0000 ; STDIN.reopen( '/dev/null') ; STDOUT.reopen( '/dev/null', 'a' ) ; STDERR.reopen( STDOUT ) nil # return nil for child process, just like fork does end |
#restart ⇒ Object
39 |
# File 'lib/runtime/worker.rb', line 39 def restart ; stop ; start ; end |
#set_traps ⇒ Object
48 49 50 51 |
# File 'lib/runtime/worker.rb', line 48 def set_traps safe_trap( 'HUP' ) { restart } safe_trap( 'TERM','INT' ) { stop } end |
#start ⇒ Object
returns the PID of the new process
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/runtime/worker.rb', line 22 def start pid = daemonize if [ :daemon ] return pid if pid # from here on in, we're in the daemon start_logger ; Waves::Logger.info "#{self.class} starting ..." start_debugger if debug? unless Kernel.engine == 'jruby' # various ways to talk to a worker set_traps ; start_console ; start_drb start_tasks.join end |
#start_console ⇒ Object
58 59 60 61 62 63 |
# File 'lib/runtime/worker.rb', line 58 def start_console if config.console @console = config.console ; @console.start Waves::Logger.info "Console started on port #{config.console.port}" end end |
#start_debugger ⇒ Object
65 66 67 68 69 |
# File 'lib/runtime/worker.rb', line 65 def start_debugger require 'ruby-debug' ; Debugger.start Debugger.settings[:autoeval] = true if Debugger.respond_to?(:settings) Waves::Logger.info "ruby-debug enabled" end |