Class: ActiveJob::Scheduler::Cli
- Inherits:
-
Object
- Object
- ActiveJob::Scheduler::Cli
- Defined in:
- lib/active_job/scheduler/cli.rb
Overview
Controller for the schedule via the CLI.
Constant Summary collapse
- USAGE =
A short doc explaining the CLI.
<<-EOF.gsub(/ {6}/, '') Usage: activejob-scheduler [options] Runs an active_job scheduler process directly (rather than via rake). EOF
- OPTIONS =
The various options our CLI takes.
[ { args: ['-n', '--app-name [APP_NAME]', 'Application name for procline'], callback: ->() { ->(n) { [:app_name] = n } } }, { args: ['-B', '--background', 'Run in the background [BACKGROUND]'], callback: ->() { ->(b) { [:background] = b } } }, { args: ['-D', '--dynamic-schedule', 'Enable dynamic scheduling [DYNAMIC_SCHEDULE]'], callback: ->() { ->(d) { [:dynamic] = d } } }, { args: ['-E', '--environment [RAILS_ENV]', 'Environment name'], callback: ->() { ->(e) { [:env] = e } } }, { args: ['-I', '--initializer-path [INITIALIZER_PATH]', 'Path to optional initializer ruby file'], callback: ->() { ->(i) { [:initializer_path] = i } } }, { args: ['-i', '--interval [RESQUE_SCHEDULER_INTERVAL]', 'Interval for checking if a scheduled job must run'], callback: ->() { ->(i) { [:poll_sleep_amount] = i } } }, { args: ['-l', '--logfile [LOGFILE]', 'Log file name'], callback: ->() { ->(l) { [:logfile] = l } } }, { args: ['-F', '--logformat [LOGFORMAT]', 'Log output format'], callback: ->() { ->(f) { [:logformat] = f } } }, { args: ['-P', '--pidfile [PIDFILE]', 'PID file name'], callback: ->() { ->(p) { [:pidfile] = p } } }, { args: ['-q', '--quiet', 'Run with minimal output [QUIET]'], callback: ->() { ->(q) { [:quiet] = q } } }, { args: ['-v', '--verbose', 'Run with verbose output [VERBOSE]'], callback: ->() { ->(v) { [:verbose] = v } } } ].freeze
Instance Attribute Summary collapse
-
#env ⇒ Object
readonly
Returns the value of attribute env.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Class Method Summary collapse
-
.run(argv, env) ⇒ Object
Start the scheduler CLI immediately from given command-line arguments.
Instance Method Summary collapse
-
#initialize(argv, env) ⇒ Cli
constructor
Instantiate a new CLI handler with the given args.
-
#run ⇒ Object
Now that we have args, actually begin running the schedule by loading each Job into Rufus::Scheduler.
Constructor Details
#initialize(argv, env) ⇒ Cli
Instantiate a new CLI handler with the given args.
69 70 71 72 73 |
# File 'lib/active_job/scheduler/cli.rb', line 69 def initialize(argv, env) @env = env @args = argv @options = option_parser.parse! argv end |
Instance Attribute Details
#env ⇒ Object (readonly)
Returns the value of attribute env.
6 7 8 |
# File 'lib/active_job/scheduler/cli.rb', line 6 def env @env end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
6 7 8 |
# File 'lib/active_job/scheduler/cli.rb', line 6 def @options end |
Class Method Details
.run(argv, env) ⇒ Object
Start the scheduler CLI immediately from given command-line arguments.
77 78 79 |
# File 'lib/active_job/scheduler/cli.rb', line 77 def self.run(argv, env) new(argv, env).run end |
Instance Method Details
#run ⇒ Object
Now that we have args, actually begin running the schedule by loading each Job into Rufus::Scheduler. Rufus uses methods like ‘every` and `cron` to determine what kind of job you’re pushing into it, so we use send() to give the Job object the power to make that choice.
86 87 88 89 90 91 92 |
# File 'lib/active_job/scheduler/cli.rb', line 86 def run jobs.each do |job| rufus.send job.interval, *job.rufus_params end rufus.start end |