Class: PerfectQueue::Supervisor
- Inherits:
-
Object
- Object
- PerfectQueue::Supervisor
- Defined in:
- lib/perfectqueue/supervisor.rb
Instance Attribute Summary collapse
-
#engine ⇒ Object
readonly
Returns the value of attribute engine.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(runner, config = nil, &block) ⇒ Supervisor
constructor
A new instance of Supervisor.
- #logrotated ⇒ Object
- #replace(immediate, command = [$0]+ARGV) ⇒ Object
- #restart(immediate) ⇒ Object
- #run ⇒ Object
- #stop(immediate) ⇒ Object
Constructor Details
#initialize(runner, config = nil, &block) ⇒ Supervisor
Returns a new instance of Supervisor.
26 27 28 29 30 31 32 33 34 |
# File 'lib/perfectqueue/supervisor.rb', line 26 def initialize(runner, config=nil, &block) # initial logger STDERR.sync = true @log = DaemonsLogger.new(STDERR) @runner = runner block = Proc.new { config } if config @config_load_proc = block end |
Instance Attribute Details
#engine ⇒ Object (readonly)
Returns the value of attribute engine.
36 37 38 |
# File 'lib/perfectqueue/supervisor.rb', line 36 def engine @engine end |
Class Method Details
.run(runner, config = nil, &block) ⇒ Object
22 23 24 |
# File 'lib/perfectqueue/supervisor.rb', line 22 def self.run(runner, config=nil, &block) new(runner, config, &block).run end |
Instance Method Details
#logrotated ⇒ Object
95 96 97 98 99 100 |
# File 'lib/perfectqueue/supervisor.rb', line 95 def logrotated @log.info "reopen a log file" @engine.logrotated @log.reopen! return true end |
#replace(immediate, command = [$0]+ARGV) ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/perfectqueue/supervisor.rb', line 83 def replace(immediate, command=[$0]+ARGV) @log.info immediate ? "Received immediate binary replace" : "Received graceful binary replace" begin @engine.replace(immediate, command) rescue @log.error "failed to replace: #{$!}" $!.backtrace.each {|bt| @log.warn "\t#{bt}" } return false end return true end |
#restart(immediate) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/perfectqueue/supervisor.rb', line 71 def restart(immediate) @log.info immediate ? "Received immediate restart" : "Received graceful restart" begin @engine.restart(immediate, load_config) rescue @log.error "failed to restart: #{$!}" $!.backtrace.each {|bt| @log.warn "\t#{bt}" } return false end return true end |
#run ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/perfectqueue/supervisor.rb', line 38 def run @log.info "PerfectQueue #{VERSION}" install_signal_handlers do config = load_config @engine = Engine.new(@runner, config) listen_debug_server(config) begin @engine.run ensure @engine.shutdown(true) end end return nil rescue @log.error "#{$!.class}: #{$!}" $!.backtrace.each {|x| @log.warn "\t#{x}" } return nil end |
#stop(immediate) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/perfectqueue/supervisor.rb', line 59 def stop(immediate) @log.info immediate ? "Received immediate stop" : "Received graceful stop" begin @engine.stop(immediate) if @engine rescue @log.error "failed to stop: #{$!}" $!.backtrace.each {|bt| @log.warn "\t#{bt}" } return false end return true end |