Class: Guard::Resque

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

Constant Summary collapse

DEFAULT_SIGNAL =
:QUIT
DEFAULT_QUEUE =
'*'.freeze
DEFAULT_COUNT =
1
DEFAULT_TASK_SINGLE =
'resque:work'.freeze
DEFAULT_TASK_MULTIPLE =
'resque:workers'.freeze

Instance Method Summary collapse

Constructor Details

#initialize(watchers = [], options = {}) ⇒ Resque

Allowable options are:

- :environment  e.g. 'test'
- :task .e.g 'resque:work'
- :queue e.g. '*'
- :count e.g. 3
- :interval e.g. 5
- :verbose e.g. true
- :vverbose e.g. true
- :trace e.g. true
- :stop_signal e.g. :QUIT or :SIGQUIT


24
25
26
27
28
29
30
31
32
# File 'lib/guard/resque.rb', line 24

def initialize(watchers = [], options = {})
  @options = options
  @pid = nil
  @stop_signal = options[:stop_signal] || DEFAULT_SIGNAL
  @options[:queue] ||= DEFAULT_QUEUE
  @options[:count] ||= DEFAULT_COUNT
  @options[:task] ||= (@options[:count].to_i == 1) ? DEFAULT_TASK_SINGLE : DEFAULT_TASK_MULTIPLE
  super
end

Instance Method Details

#reloadObject

Called on Ctrl-Z signal



65
66
67
68
# File 'lib/guard/resque.rb', line 65

def reload
  UI.info 'Restarting resque...'
  restart
end

#restartObject



80
81
82
83
# File 'lib/guard/resque.rb', line 80

def restart
  stop
  start
end

#run_allObject

Called on Ctrl-/ signal



71
72
73
# File 'lib/guard/resque.rb', line 71

def run_all
  true
end

#run_on_change(paths) ⇒ Object

Called on file(s) modifications



76
77
78
# File 'lib/guard/resque.rb', line 76

def run_on_change(paths)
  restart
end

#startObject



34
35
36
37
38
39
40
41
# File 'lib/guard/resque.rb', line 34

def start
  stop
  UI.info 'Starting up resque...'
  UI.info [ cmd, env.map{|v| v.join('=')} ].join(' ')

  # launch Resque worker
  @pid = spawn(env, cmd)
end

#stopObject



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/guard/resque.rb', line 43

def stop
  if @pid
    UI.info 'Stopping resque...'
    ::Process.kill @stop_signal, @pid
    begin
      Timeout.timeout(15) do
        ::Process.wait @pid
      end
    rescue Timeout::Error
      UI.info 'Sending SIGKILL to resque, as it\'s taking too long to shutdown.'
      ::Process.kill :KILL, @pid
      ::Process.wait @pid
    end
    UI.info 'Stopped process resque'
  end
rescue Errno::ESRCH
  UI.info 'Guard::Resque lost the Resque worker subprocess!'
ensure
  @pid = nil
end