lib/good_job/configuration.rb in good_job-1.7.1 vs lib/good_job/configuration.rb in good_job-1.8.0
- old
+ new
@@ -11,10 +11,12 @@
DEFAULT_POLL_INTERVAL = 10
# Default number of threads to use per {Scheduler}
DEFAULT_MAX_CACHE = 10000
# Default number of seconds to preserve jobs for {CLI#cleanup_preserved_jobs}
DEFAULT_CLEANUP_PRESERVED_JOBS_BEFORE_SECONDS_AGO = 24 * 60 * 60
+ # Default to always wait for jobs to finish for {#shutdown}
+ DEFAULT_SHUTDOWN_TIMEOUT = -1
# The options that were explicitly set when initializing +Configuration+.
# @return [Hash]
attr_reader :options
@@ -75,14 +77,14 @@
# individual schedulers.
# @return [Integer]
def max_threads
(
options[:max_threads] ||
- rails_config[:max_threads] ||
- env['GOOD_JOB_MAX_THREADS'] ||
- env['RAILS_MAX_THREADS'] ||
- DEFAULT_MAX_THREADS
+ rails_config[:max_threads] ||
+ env['GOOD_JOB_MAX_THREADS'] ||
+ env['RAILS_MAX_THREADS'] ||
+ DEFAULT_MAX_THREADS
).to_i
end
# Describes which queues to execute jobs from and how those queues should
# be grouped into {Scheduler} instances. See
@@ -101,13 +103,13 @@
# poll (using this interval) for new queued jobs to execute.
# @return [Integer]
def poll_interval
(
options[:poll_interval] ||
- rails_config[:poll_interval] ||
- env['GOOD_JOB_POLL_INTERVAL'] ||
- DEFAULT_POLL_INTERVAL
+ rails_config[:poll_interval] ||
+ env['GOOD_JOB_POLL_INTERVAL'] ||
+ DEFAULT_POLL_INTERVAL
).to_i
end
# The maximum number of future-scheduled jobs to store in memory.
# Storing future-scheduled jobs in memory reduces execution latency
@@ -120,18 +122,30 @@
env['GOOD_JOB_MAX_CACHE'] ||
DEFAULT_MAX_CACHE
).to_i
end
+ # The number of seconds to wait for jobs to finish when shutting down
+ # before stopping the thread. +-1+ is forever.
+ # @return [Numeric]
+ def shutdown_timeout
+ (
+ options[:shutdown_timeout] ||
+ rails_config[:shutdown_timeout] ||
+ env['GOOD_JOB_SHUTDOWN_TIMEOUT'] ||
+ DEFAULT_SHUTDOWN_TIMEOUT
+ ).to_f
+ end
+
# Number of seconds to preserve jobs when using the +good_job cleanup_preserved_jobs+ CLI command.
# This configuration is only used when {GoodJob.preserve_job_records} is +true+.
# @return [Integer]
def cleanup_preserved_jobs_before_seconds_ago
(
options[:before_seconds_ago] ||
- rails_config[:cleanup_preserved_jobs_before_seconds_ago] ||
- env['GOOD_JOB_CLEANUP_PRESERVED_JOBS_BEFORE_SECONDS_AGO'] ||
- DEFAULT_CLEANUP_PRESERVED_JOBS_BEFORE_SECONDS_AGO
+ rails_config[:cleanup_preserved_jobs_before_seconds_ago] ||
+ env['GOOD_JOB_CLEANUP_PRESERVED_JOBS_BEFORE_SECONDS_AGO'] ||
+ DEFAULT_CLEANUP_PRESERVED_JOBS_BEFORE_SECONDS_AGO
).to_i
end
# Tests whether to daemonize the process.
# @return [Boolean]