class Guard::Delayed

Public Class Methods

new(options = {}) click to toggle source

Allowable options are: :environment defaults to 'test' :min_priority e.g. 2 :max_priority e.g. 10 :number_of_workers e.g. 2 :pid_dir e.g. tmp/pids Specifies an alternate directory in which to store the process ids. :identifier A numeric identifier for the worker. :monitor Start monitor process. :sleep-delay N Amount of time to sleep in seconds when no jobs are found :prefix NAME String to be prefixed to worker process names :root directory to find the executable. Defaults to '' :command Command to execute. Default to 'bin/delayed_job'

Calls superclass method
# File lib/guard/delayed.rb, line 19
def initialize(options = {})
  super
  @options = options
  @options[:command] = 'bin/delayed_job' unless @options[:command]
end

Public Instance Methods

reload() click to toggle source

Called on Ctrl-Z signal This method should be mainly used for “reload” (really!) actions like reloading passenger/spork/bundler/…

# File lib/guard/delayed.rb, line 46
def reload
  restart
end
run_all() click to toggle source

Called on Ctrl-/ signal This method should be principally used for long action like running all specs/tests/…

# File lib/guard/delayed.rb, line 52
def run_all
  restart
end
run_on_changes(paths) click to toggle source

Called on file(s) modifications

# File lib/guard/delayed.rb, line 57
def run_on_changes(paths)
  restart
end
start() click to toggle source
# File lib/guard/delayed.rb, line 25
def start
  run_cmd("stop")
  parameters  = "start"
  parameters << " --min-priority #{@options[:min_priority]}" if @options[:min_priority]
  parameters << " --max-priority #{@options[:max_priority]}" if @options[:max_priority]
  parameters << " --number_of_workers=#{@options[:number_of_workers]}" if @options[:number_of_workers]
  parameters << " --pid-dir=#{@options[:pid_dir]}" if @options[:pid_dir]
  parameters << " --identifier=#{@options[:identifier]}" if @options[:identifier]
  parameters << " --monitor" if @options[:monitor]
  parameters << " --sleep-delay #{@options[:sleep_delay]}" if @options[:sleep_delay]
  parameters << " --prefix #{@options[:prefix]} " if @options[:prefix]
  run_cmd(parameters)
end
stop() click to toggle source

Called on Ctrl-C signal (when Guard quits)

# File lib/guard/delayed.rb, line 40
def stop
  run_cmd("stop")
end

Private Instance Methods

cmd() click to toggle source
# File lib/guard/delayed.rb, line 67
def cmd
  command = @options[:command]
  command = "#{@options[:root]}/#{command}" if @options[:root]
  command = "export RAILS_ENV=#{@options[:environment]}; #{command}" if @options[:environment]
  command
end
restart() click to toggle source
# File lib/guard/delayed.rb, line 63
def restart
  run_cmd('restart')
end
run_cmd(parameters) click to toggle source
# File lib/guard/delayed.rb, line 74
def run_cmd(parameters)
  sys_response = system("#{cmd} #{parameters}")
  raise StandardError, "Bad command: #{cmd} #{parameters}" if sys_response.nil? || !sys_response
  sys_response
end