Class: Cron::Command
- Inherits:
-
Object
- Object
- Cron::Command
- Defined in:
- lib/app/jobs/cron/command.rb
Overview
rubocop:disable ClassLength
Constant Summary collapse
- DIR_PWD =
Pathname.new Dir.pwd
Instance Method Summary collapse
-
#daemonize ⇒ Object
rubocop:disable PerceivedComplexity.
-
#initialize(args) ⇒ Command
constructor
rubocop:disable MethodLength.
- #run(options = {}) ⇒ Object
Constructor Details
#initialize(args) ⇒ Command
rubocop:disable MethodLength
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) # rubocop:disable MethodLength @options = { pid_dir: "#{root}/tmp/pids", log_dir: "#{root}/log", monitor: false } opts = OptionParser.new do |opt| opt. = "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 = end end @args = opts.parse!(args) + (@daemon_options || []) end |
Instance Method Details
#daemonize ⇒ Object
rubocop:disable PerceivedComplexity
49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/app/jobs/cron/command.rb', line 49 def daemonize # rubocop:disable PerceivedComplexity dir = @options[:pid_dir] FileUtils.mkdir_p(dir) unless File.exist?(dir) Cron::JobTab.ensure_cron_tabs Cron::Worker.logger ||= Logger.new(File.join(@options[:log_dir], 'cron.log')) Daemons.run_proc('cron_server', dir: [:pid_dir], dir_mode: :normal, monitor: @options[:monitor], ARGV: @args) do run @options end end |