Class: Guard::ResqueScheduler
- Defined in:
- lib/guard/resque-scheduler.rb
Constant Summary collapse
- DEFAULT_SIGNAL =
:QUIT
- DEFAULT_TASK =
'resque:scheduler'.freeze
Instance Method Summary collapse
-
#initialize(watchers = [], options = {}) ⇒ ResqueScheduler
constructor
Allowable options are: - :environment e.g.
-
#reload ⇒ Object
Called on Ctrl-Z signal.
- #restart ⇒ Object
-
#run_all ⇒ Object
Called on Ctrl-/ signal.
-
#run_on_change(paths) ⇒ Object
Called on file(s) modifications.
- #start ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(watchers = [], options = {}) ⇒ ResqueScheduler
Allowable options are:
- :environment e.g. 'test'
- :task e.g 'resque:scheduler'
- :verbose e.g. true
- :trace e.g. true
- :stop_signal e.g. :QUIT or :SIGQUIT
17 18 19 20 21 22 23 24 |
# File 'lib/guard/resque-scheduler.rb', line 17 def initialize(watchers = [], = {}) @options = @pid = nil @stop_signal = [:stop_signal] || DEFAULT_SIGNAL @options[:task] ||= DEFAULT_TASK @first_start = true super end |
Instance Method Details
#reload ⇒ Object
Called on Ctrl-Z signal
59 60 61 62 |
# File 'lib/guard/resque-scheduler.rb', line 59 def reload UI.info 'Restarting resque-scheduler...' @pid ? stop : start end |
#restart ⇒ Object
74 75 76 77 |
# File 'lib/guard/resque-scheduler.rb', line 74 def restart stop start end |
#run_all ⇒ Object
Called on Ctrl-/ signal
65 66 67 |
# File 'lib/guard/resque-scheduler.rb', line 65 def run_all true end |
#run_on_change(paths) ⇒ Object
Called on file(s) modifications
70 71 72 |
# File 'lib/guard/resque-scheduler.rb', line 70 def run_on_change(paths) restart end |
#start ⇒ Object
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/guard/resque-scheduler.rb', line 26 def start stop UI.info 'Starting up resque-scheduler...' UI.info [ cmd, env.map{|v| v.join('=')} ].join(' ') # Launch ResqueScheduler @first_start ? @first_start = false : @pid = spawn(env, cmd) end |
#stop ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/guard/resque-scheduler.rb', line 37 def stop if @pid UI.info 'Stopping resque-scheduler...' ::Process.kill @stop_signal, @pid begin Timeout.timeout(15) do ::Process.wait @pid end rescue Timeout::Error UI.info 'Sending SIGKILL to resque-scheduler, as it\'s taking too long to shutdown.' ::Process.kill :KILL, @pid ::Process.wait @pid end UI.info 'Stopped process resque-scheduler' end rescue Errno::ESRCH UI.info 'Guard::ResqueScheduler lost the ResqueScheduler worker subprocess!' ensure @pid = nil end |