Class: Guard::ResqueScheduler

Inherits:
Guard
  • Object
show all
Defined in:
lib/guard/resque-scheduler.rb

Constant Summary collapse

DEFAULT_SIGNAL =
:QUIT
DEFAULT_TASK =
'resque:scheduler'.freeze

Instance Method Summary collapse

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 = {})
  @options = options
  @pid = nil
  @stop_signal = options[:stop_signal] || DEFAULT_SIGNAL
  @options[:task] ||= DEFAULT_TASK
  @first_start = true
  super
end

Instance Method Details

#reloadObject

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

#restartObject



74
75
76
77
# File 'lib/guard/resque-scheduler.rb', line 74

def restart
  stop
  start
end

#run_allObject

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

#startObject



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

#stopObject



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