Class: GoodJob::Configuration
- Inherits:
-
Object
- Object
- GoodJob::Configuration
- Defined in:
- lib/good_job/configuration.rb
Overview
GoodJob::Configuration
provides normalized configuration information to the rest of GoodJob. It combines environment information with explicitly set options to get the final values for each option.
Constant Summary collapse
- DEFAULT_MAX_THREADS =
Default number of threads to use per Scheduler
5
- DEFAULT_POLL_INTERVAL =
Default number of seconds between polls for jobs
5
- DEFAULT_CLEANUP_PRESERVED_JOBS_BEFORE_SECONDS_AGO =
Default number of seconds to preserve jobs for GoodJob::CLI#cleanup_preserved_jobs
24 * 60 * 60
Instance Attribute Summary collapse
-
#env ⇒ Object
readonly
Returns the value of attribute env.
-
#options ⇒ Hash
readonly
The options that were explicitly set when initializing
Configuration
.
Instance Method Summary collapse
- #cleanup_preserved_jobs_before_seconds_ago ⇒ Object
-
#execution_mode(default: :external) ⇒ Symbol
Specifies how and where jobs should be executed.
-
#initialize(options, env: ENV) ⇒ Configuration
constructor
A new instance of Configuration.
-
#max_threads ⇒ Integer
Indicates the number of threads to use per Scheduler.
-
#poll_interval ⇒ Integer
The number of seconds between polls for jobs.
-
#queue_string ⇒ String
Describes which queues to execute jobs from and how those queues should be grouped into Scheduler instances.
-
#rails_execution_mode ⇒ Symbol
Like #execution_mode, but takes the current Rails environment into account (e.g. in the
test
environment, it falls back to:inline
).
Constructor Details
#initialize(options, env: ENV) ⇒ Configuration
Returns a new instance of Configuration.
30 31 32 33 |
# File 'lib/good_job/configuration.rb', line 30 def initialize(, env: ENV) @options = @env = env end |
Instance Attribute Details
#env ⇒ Object (readonly)
Returns the value of attribute env.
24 |
# File 'lib/good_job/configuration.rb', line 24 attr_reader :options, :env |
#options ⇒ Hash (readonly)
The options that were explicitly set when initializing Configuration
.
24 25 26 |
# File 'lib/good_job/configuration.rb', line 24 def @options end |
Instance Method Details
#cleanup_preserved_jobs_before_seconds_ago ⇒ Object
106 107 108 109 110 111 112 |
# File 'lib/good_job/configuration.rb', line 106 def cleanup_preserved_jobs_before_seconds_ago ( [:before_seconds_ago] || env['GOOD_JOB_CLEANUP_PRESERVED_JOBS_BEFORE_SECONDS_AGO'] || DEFAULT_CLEANUP_PRESERVED_JOBS_BEFORE_SECONDS_AGO ).to_i end |
#execution_mode(default: :external) ⇒ Symbol
Specifies how and where jobs should be executed. See Adapter#initialize for more details on possible values.
When running inside a Rails app, you may want to use #rails_execution_mode, which takes the current Rails environment into account when determining the final value.
45 46 47 48 49 50 51 52 53 |
# File 'lib/good_job/configuration.rb', line 45 def execution_mode(default: :external) if [:execution_mode] [:execution_mode] elsif env['GOOD_JOB_EXECUTION_MODE'].present? env['GOOD_JOB_EXECUTION_MODE'].to_sym else default end end |
#max_threads ⇒ Integer
Indicates the number of threads to use per Scheduler. Note that #queue_string may provide more specific thread counts to use with individual schedulers.
74 75 76 77 78 79 80 81 |
# File 'lib/good_job/configuration.rb', line 74 def max_threads ( [:max_threads] || env['GOOD_JOB_MAX_THREADS'] || env['RAILS_MAX_THREADS'] || DEFAULT_MAX_THREADS ).to_i end |
#poll_interval ⇒ Integer
The number of seconds between polls for jobs. GoodJob will execute jobs on queues continuously until a queue is empty, at which point it will poll (using this interval) for new queued jobs to execute.
98 99 100 101 102 103 104 |
# File 'lib/good_job/configuration.rb', line 98 def poll_interval ( [:poll_interval] || env['GOOD_JOB_POLL_INTERVAL'] || DEFAULT_POLL_INTERVAL ).to_i end |
#queue_string ⇒ String
88 89 90 91 92 |
# File 'lib/good_job/configuration.rb', line 88 def queue_string [:queues] || env['GOOD_JOB_QUEUES'] || '*' end |
#rails_execution_mode ⇒ Symbol
Like #execution_mode, but takes the current Rails environment into account (e.g. in the test
environment, it falls back to :inline
).
58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/good_job/configuration.rb', line 58 def rails_execution_mode if execution_mode(default: nil) execution_mode elsif Rails.env.development? :inline elsif Rails.env.test? :inline else :external end end |