lib/good_job/cli.rb in good_job-1.11.3 vs lib/good_job/cli.rb in good_job-1.12.0

- old
+ new

@@ -68,16 +68,20 @@ desc: "Maximum number of scheduled jobs to cache in memory (env var: GOOD_JOB_MAX_CACHE, default: 10000)" method_option :shutdown_timeout, type: :numeric, banner: 'SECONDS', desc: "Number of seconds to wait for jobs to finish when shutting down before stopping the thread. (env var: GOOD_JOB_SHUTDOWN_TIMEOUT, default: -1 (forever))" + method_option :enable_cron, + type: :boolean, + desc: "Whether to run cron process (default: false)" method_option :daemonize, type: :boolean, desc: "Run as a background daemon (default: false)" method_option :pidfile, type: :string, desc: "Path to write daemonized Process ID (env var: GOOD_JOB_PIDFILE, default: tmp/pids/good_job.pid)" + def start set_up_application! configuration = GoodJob::Configuration.new(options) Daemon.new(pidfile: configuration.pidfile).daemonize if configuration.daemonize? @@ -85,22 +89,22 @@ notifier = GoodJob::Notifier.new poller = GoodJob::Poller.new(poll_interval: configuration.poll_interval) scheduler = GoodJob::Scheduler.from_configuration(configuration, warm_cache_on_initialize: true) notifier.recipients << [scheduler, :create_thread] poller.recipients << [scheduler, :create_thread] - + cron_manager = GoodJob::CronManager.new(configuration.cron, start_on_initialize: true) if configuration.enable_cron? @stop_good_job_executable = false %w[INT TERM].each do |signal| trap(signal) { @stop_good_job_executable = true } end Kernel.loop do sleep 0.1 break if @stop_good_job_executable || scheduler.shutdown? || notifier.shutdown? end - executors = [notifier, poller, scheduler] + executors = [notifier, poller, cron_manager, scheduler].compact GoodJob._shutdown_all(executors, timeout: configuration.shutdown_timeout) end default_task :start @@ -122,9 +126,10 @@ DESCRIPTION method_option :before_seconds_ago, type: :numeric, banner: 'SECONDS', desc: "Delete records finished more than this many seconds ago (env var: GOOD_JOB_CLEANUP_PRESERVED_JOBS_BEFORE_SECONDS_AGO, default: 86400)" + def cleanup_preserved_jobs set_up_application! configuration = GoodJob::Configuration.new(options)