Class: Cron::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/app/jobs/cron/command.rb

Constant Summary collapse

DIR_PWD =
Pathname.new Dir.pwd

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Command

Returns a new instance of Command.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/app/jobs/cron/command.rb', line 17

def initialize(args)
  @options = { pid_dir: "#{root}/tmp/pids", log_dir: "#{root}/log", monitor: false }

  opts = OptionParser.new do |opt|
    opt.banner = "Usage: #{File.basename($PROGRAM_NAME)} [options] start|stop|restart|run"

    opt.on('-h', '--help', 'Show this message') do
      puts opt
      exit 1
    end
    opt.on('-e', '--environment=NAME', 'Specifies the environment to run this delayed jobs under (test/development/production).') do |_e|
      STDERR.puts 'The -e/--environment option has been deprecated and has no effect. Use RAILS_ENV and see http://github.com/collectiveidea/delayed_job/issues/7'
    end
    opt.on('--pid-dir=DIR', 'Specifies an alternate directory in which to store the process ids.') do |dir|
      @options[:pid_dir] = dir
    end
    opt.on('--log-dir=DIR', 'Specifies an alternate directory in which to store the delayed_job log.') do |dir|
      @options[:log_dir] = dir
    end
    opt.on('-m', '--monitor', 'Start monitor process.') do
      @options[:monitor] = true
    end
    opt.on('--exit-on-complete', 'Exit when no more jobs are available to run. This will exit if all jobs are scheduled to run in the future.') do
      @options[:exit_on_complete] = true
    end
    opt.on('--daemon-options a, b, c', Array, 'options to be passed through to daemons gem') do |daemon_options|
      @daemon_options = daemon_options
    end
  end
  @args = opts.parse!(args) + (@daemon_options || [])
end

Instance Method Details

#daemonize ⇒ Object



49
50
51
52
53
54
55
56
57
# File 'lib/app/jobs/cron/command.rb', line 49

def daemonize
  dir = @options[:pid_dir]
  FileUtils.mkdir_p(dir) unless File.exist?(dir)

  Cron::JobTab.ensure_cron_tabs
  Daemons.run_proc('cron_server', dir: @options[:pid_dir], monitor: @options[:monitor], ARGV: @args) do
    loop { sleep Cron::Server.find_or_create_server.execute }
  end
end