Class: Exekutor::Configuration
- Inherits:
-
Object
- Object
- Exekutor::Configuration
- Includes:
- Internal::ConfigurationBuilder
- Defined in:
- lib/exekutor/configuration.rb
Overview
Configuration for the Exekutor library
Defined Under Namespace
Classes: Error, SerializerValidator
Instance Method Summary collapse
-
#base_record_class ⇒ Class
Gets the base class for database records.
-
#base_record_class_name ⇒ String
Gets the base class name for database records.
-
#base_record_class_name=(value) ⇒ self
Sets the base class name for database records.
-
#default_queue_priority ⇒ Integer
Gets the default queue priority.
-
#default_queue_priority=(value) ⇒ self
Sets the default queue priority.
-
#delete_completed_jobs=(value) ⇒ self
Sets whether the worker should delete jobs after completion.
-
#delete_completed_jobs? ⇒ Boolean
Whether the worker should delete jobs after completion.
-
#delete_discarded_jobs=(value) ⇒ self
Sets whether the worker should delete discarded jobs.
-
#delete_discarded_jobs? ⇒ Boolean
Whether the worker should delete discarded jobs.
-
#delete_failed_jobs=(value) ⇒ self
Sets whether the worker should delete jobs after they failed to execute.
-
#delete_failed_jobs? ⇒ Boolean
Whether the worker should delete jobs after they failed to execute.
-
#enable_listener=(value) ⇒ self
Sets whether the worker should use LISTEN/NOTIFY to listen for jobs.
-
#enable_listener? ⇒ Boolean?
Whether the worker should use LISTEN/NOTIFY to listen for jobs.
-
#healthcheck_timeout=(value) ⇒ self
Sets the heartbeat timeout for the ‘/live` endpoint of the status server.
-
#healthcheck_timeout? ⇒ ActiveSupport::Duration
The heartbeat timeout for the ‘/live` endpoint of the status server.
-
#inverse_priority=(value) ⇒ self
Sets whether the the priority should be inverted.
-
#inverse_priority? ⇒ Boolean
Whether the priority should be inverted.
-
#json_serializer ⇒ String, ...
Gets the unconverted JSON serializer value.
-
#json_serializer=(value) ⇒ self
Sets the JSON serializer.
-
#load_json_serializer ⇒ Object
Gets the JSON serializer.
-
#logger ⇒ ActiveSupport::Logger
Gets the logger.
-
#logger=(value) ⇒ self
Sets the logger.
-
#max_execution_thread_idletime ⇒ ActiveSupport::Duration
The maximum duration a thread may be idle before being stopped.
-
#max_execution_thread_idletime=(value) ⇒ self
Sets the maximum duration a thread may be idle before being stopped.
-
#max_execution_threads ⇒ Integer
The maximum number of execution threads that may be active.
-
#max_execution_threads=(value) ⇒ self
Sets the maximum number of execution threads that may be active.
-
#min_execution_threads ⇒ Integer
The minimum number of execution threads that should be active.
-
#min_execution_threads=(value) ⇒ self
Sets the minimum number of execution threads that should be active.
-
#polling_interval ⇒ ActiveSupport::Duration
The polling interval.
-
#polling_interval=(value) ⇒ self
Sets the polling interval.
-
#polling_jitter ⇒ Float
The polling jitter, used to adjust the polling interval slightly so multiple workers will not query the database at the same time.
-
#polling_jitter=(value) ⇒ self
Sets the polling jitter, which is used to slightly adjust the polling interval.
-
#quiet=(value) ⇒ self
Sets whether the STDOUT messages should be printed.
-
#quiet? ⇒ Boolean
Whether to suppress STDOUT messages === Default value: false.
-
#set_db_connection_name=(value) ⇒ self
Sets whether the DB connection name should be set.
-
#set_db_connection_name? ⇒ Boolean?
Whether the DB connection name should be set.
-
#status_server_handler=(value) ⇒ self
Sets the rack handler for the status server.
-
#status_server_handler? ⇒ String
The rack handler for the status server === Default value: “webrick”.
-
#status_server_port=(value) ⇒ self
Sets the port number for the status server.
-
#status_server_port? ⇒ Integer
The port number for the status server === Default value:
nil
(ie. the status server is disabled). -
#worker_options ⇒ Hash
Gets the options for a worker.
Methods included from Internal::ConfigurationBuilder
#set, #validate_option_enum!, #validate_option_presence!, #validate_option_range!, #validate_option_type!
Instance Method Details
#base_record_class ⇒ Class
Gets the base class for database records. Is derived from the #base_record_class_name option.
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/exekutor/configuration.rb', line 48 def base_record_class const_get :base_record_class_name rescue ::StandardError # A nicer message for the default value if base_record_class_name == DEFAULT_BASE_RECORD_CLASS raise Error, "Cannot find ActiveRecord, did you install and load the gem?" end raise end |
#base_record_class_name ⇒ String
Gets the base class name for database records.
Default value:
“ActiveRecord::Base”
43 |
# File 'lib/exekutor/configuration.rb', line 43 define_option :base_record_class_name, default: DEFAULT_BASE_RECORD_CLASS, required: true, type: String |
#base_record_class_name=(value) ⇒ self
Sets the base class name for database records. The validity of this value will not be checked immediately. (Ie. When the specified class does not exist, an error will raised when a database record is used for the first time.)
43 |
# File 'lib/exekutor/configuration.rb', line 43 define_option :base_record_class_name, default: DEFAULT_BASE_RECORD_CLASS, required: true, type: String |
#default_queue_priority ⇒ Integer
Gets the default queue priority. Is used when enqueueing jobs that don’t have a priority set.
Default value:
16,383
27 28 |
# File 'lib/exekutor/configuration.rb', line 27 define_option :default_queue_priority, default: 16_383, required: true, type: Integer, range: Exekutor::Queue::VALID_PRIORITIES |
#default_queue_priority=(value) ⇒ self
Sets the default queue priority. Is used when enqueueing jobs that don’t have a priority set. Should be between 1 and 32,767.
27 28 |
# File 'lib/exekutor/configuration.rb', line 27 define_option :default_queue_priority, default: 16_383, required: true, type: Integer, range: Exekutor::Queue::VALID_PRIORITIES |
#delete_completed_jobs=(value) ⇒ self
Sets whether the worker should delete jobs after completion
152 153 |
# File 'lib/exekutor/configuration.rb', line 152 define_option :delete_completed_jobs, reader: :delete_completed_jobs?, required: true, type: [TrueClass, FalseClass], default: false |
#delete_completed_jobs? ⇒ Boolean
Whether the worker should delete jobs after completion.
Default value:
false
152 153 |
# File 'lib/exekutor/configuration.rb', line 152 define_option :delete_completed_jobs, reader: :delete_completed_jobs?, required: true, type: [TrueClass, FalseClass], default: false |
#delete_discarded_jobs=(value) ⇒ self
Sets whether the worker should delete discarded jobs
165 166 |
# File 'lib/exekutor/configuration.rb', line 165 define_option :delete_discarded_jobs, reader: :delete_discarded_jobs?, required: true, type: [TrueClass, FalseClass], default: false |
#delete_discarded_jobs? ⇒ Boolean
Whether the worker should delete discarded jobs.
Default value:
false
165 166 |
# File 'lib/exekutor/configuration.rb', line 165 define_option :delete_discarded_jobs, reader: :delete_discarded_jobs?, required: true, type: [TrueClass, FalseClass], default: false |
#delete_failed_jobs=(value) ⇒ self
Sets whether the worker should delete jobs after they failed to execute
178 179 |
# File 'lib/exekutor/configuration.rb', line 178 define_option :delete_failed_jobs, reader: :delete_failed_jobs?, required: true, type: [TrueClass, FalseClass], default: false |
#delete_failed_jobs? ⇒ Boolean
Whether the worker should delete jobs after they failed to execute.
Default value:
false
178 179 |
# File 'lib/exekutor/configuration.rb', line 178 define_option :delete_failed_jobs, reader: :delete_failed_jobs?, required: true, type: [TrueClass, FalseClass], default: false |
#enable_listener=(value) ⇒ self
Sets whether the worker should use LISTEN/NOTIFY to listen for jobs
139 140 |
# File 'lib/exekutor/configuration.rb', line 139 define_option :enable_listener, reader: :enable_listener?, default: true, type: [TrueClass, FalseClass], required: true |
#enable_listener? ⇒ Boolean?
Whether the worker should use LISTEN/NOTIFY to listen for jobs.
Default value:
true
139 140 |
# File 'lib/exekutor/configuration.rb', line 139 define_option :enable_listener, reader: :enable_listener?, default: true, type: [TrueClass, FalseClass], required: true |
#healthcheck_timeout=(value) ⇒ self
Sets the heartbeat timeout for the ‘/live` endpoint of the status server. Must be between 1 minute and 24 hours.
291 292 |
# File 'lib/exekutor/configuration.rb', line 291 define_option :healthcheck_timeout, default: 30.minutes, type: ActiveSupport::Duration, range: (1.minute)..(1.day) |
#healthcheck_timeout? ⇒ ActiveSupport::Duration
The heartbeat timeout for the ‘/live` endpoint of the status server. If the heartbeat of a worker is older than this timeout, the status server will respond with a 503 status indicating the service is down.
Default value:
30 minutes
291 292 |
# File 'lib/exekutor/configuration.rb', line 291 define_option :healthcheck_timeout, default: 30.minutes, type: ActiveSupport::Duration, range: (1.minute)..(1.day) |
#inverse_priority=(value) ⇒ self
Sets whether the the priority should be inverted. When true, the job with the highest value as the priority is the most important; when false, the job with the lowest value as the priority is the most important.
306 307 |
# File 'lib/exekutor/configuration.rb', line 306 define_option :inverse_priority, reader: :inverse_priority?, type: [TrueClass, FalseClass], required: true, default: false |
#inverse_priority? ⇒ Boolean
Whether the priority should be inverted. If true, the job with the highest value as the priority is the most important. If false, the job with the lowest value as the priority is the most important.
Default value:
false
306 307 |
# File 'lib/exekutor/configuration.rb', line 306 define_option :inverse_priority, reader: :inverse_priority?, type: [TrueClass, FalseClass], required: true, default: false |
#json_serializer ⇒ String, ...
Gets the unconverted JSON serializer value. This can be either a String
, a Symbol
, a Proc
, or the serializer.
Default value:
JSON
76 77 78 79 80 |
# File 'lib/exekutor/configuration.rb', line 76 define_option :json_serializer, default: "::JSON", required: true do |value| unless value.is_a?(String) || value.is_a?(Symbol) || value.respond_to?(:call) || SerializerValidator.valid?(value) raise Error, "#json_serializer must either be a String, a Proc, or respond to #dump and #load" end end |
#json_serializer=(value) ⇒ self
Sets the JSON serializer. This can be either a String
, a Symbol
, a Proc
, or the serializer. If a String
, Symbol
, or Proc
is given, the serializer will be loaded when it is needed for the first time. If the loaded class does not respond to #dump
and #load
an Error will be raised whenever the serializer is loaded. If the value is neither a String
, Symbol
, nor a Proc
and it does not respond to #dump
and #load
, the error will be thrown immediately.
76 77 78 79 80 |
# File 'lib/exekutor/configuration.rb', line 76 define_option :json_serializer, default: "::JSON", required: true do |value| unless value.is_a?(String) || value.is_a?(Symbol) || value.respond_to?(:call) || SerializerValidator.valid?(value) raise Error, "#json_serializer must either be a String, a Proc, or respond to #dump and #load" end end |
#load_json_serializer ⇒ Object
Gets the JSON serializer. Is derived from the #json_serializer option.
85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/exekutor/configuration.rb', line 85 def load_json_serializer raw_value = json_serializer if defined?(@json_serializer_instance) && @json_serializer_instance[0] == raw_value return @json_serializer_instance[1] end serializer = const_get :json_serializer serializer = SerializerValidator.convert! serializer unless SerializerValidator.valid? serializer @json_serializer_instance = [raw_value, serializer] serializer end |
#logger ⇒ ActiveSupport::Logger
Gets the logger.
Default value:
Rails.active_job.logger
107 |
# File 'lib/exekutor/configuration.rb', line 107 define_option :logger, default: -> { Rails.active_job.logger } |
#logger=(value) ⇒ self
Sets the logger.
107 |
# File 'lib/exekutor/configuration.rb', line 107 define_option :logger, default: -> { Rails.active_job.logger } |
#max_execution_thread_idletime ⇒ ActiveSupport::Duration
The maximum duration a thread may be idle before being stopped.
Default value:
60 seconds
251 252 |
# File 'lib/exekutor/configuration.rb', line 251 define_option :max_execution_thread_idletime, default: 1.minute, type: ActiveSupport::Duration, range: (1.second)..(1.day) |
#max_execution_thread_idletime=(value) ⇒ self
Sets the maximum duration a thread may be idle before being stopped
251 252 |
# File 'lib/exekutor/configuration.rb', line 251 define_option :max_execution_thread_idletime, default: 1.minute, type: ActiveSupport::Duration, range: (1.second)..(1.day) |
#max_execution_threads ⇒ Integer
The maximum number of execution threads that may be active.
Default value:
Active record pool size minus 1, with a minimum of 1
237 238 239 |
# File 'lib/exekutor/configuration.rb', line 237 define_option :max_execution_threads, default: -> { (Internal::BaseRecord.connection_db_config.pool.to_i - 1).clamp(1, 999) }, type: Integer, range: 1...999 |
#max_execution_threads=(value) ⇒ self
Sets the maximum number of execution threads that may be active. Be aware that if you set this to a value greater than connection_db_config.pool
, workers may have to wait for database connections to become available because all connections are occupied by other threads. This may result in an ActiveRecord::ConnectionTimeoutError
if the thread has to wait too long.
237 238 239 |
# File 'lib/exekutor/configuration.rb', line 237 define_option :max_execution_threads, default: -> { (Internal::BaseRecord.connection_db_config.pool.to_i - 1).clamp(1, 999) }, type: Integer, range: 1...999 |
#min_execution_threads ⇒ Integer
The minimum number of execution threads that should be active.
Default value:
1
222 |
# File 'lib/exekutor/configuration.rb', line 222 define_option :min_execution_threads, default: 1, type: Integer, range: 1...999 |
#min_execution_threads=(value) ⇒ self
Sets the minimum number of execution threads that should be active
222 |
# File 'lib/exekutor/configuration.rb', line 222 define_option :min_execution_threads, default: 1, type: Integer, range: 1...999 |
#polling_interval ⇒ ActiveSupport::Duration
The polling interval. When set, the worker will poll the database with this interval to check for any pending jobs that a listener might have missed (if enabled).
Default value:
60 seconds
194 195 |
# File 'lib/exekutor/configuration.rb', line 194 define_option :polling_interval, default: 1.minute, type: [ActiveSupport::Duration, nil], range: (1.second)...(1.day) |
#polling_interval=(value) ⇒ self
Sets the polling interval. Set to nil
to disable polling. If the listener is disabled, this value should be reasonably low so jobs don’t have to wait in the queue too long; if the listener is enabled, this value can be reasonably high.
194 195 |
# File 'lib/exekutor/configuration.rb', line 194 define_option :polling_interval, default: 1.minute, type: [ActiveSupport::Duration, nil], range: (1.second)...(1.day) |
#polling_jitter ⇒ Float
The polling jitter, used to adjust the polling interval slightly so multiple workers will not query the database at the same time.
Default value:
0.1
210 |
# File 'lib/exekutor/configuration.rb', line 210 define_option :polling_jitter, default: 0.1, type: [Float, Integer], range: 0..0.5 |
#polling_jitter=(value) ⇒ self
Sets the polling jitter, which is used to slightly adjust the polling interval. Should be between 0 and 0.5. A value of 0.1 means the polling interval can vary by 10%. If the interval is set to 60 seconds and the jitter is set to 0.1, the interval can range from 57 to 63 seconds. A value of 0 disables this feature.
210 |
# File 'lib/exekutor/configuration.rb', line 210 define_option :polling_jitter, default: 0.1, type: [Float, Integer], range: 0..0.5 |
#quiet=(value) ⇒ self
Sets whether the STDOUT messages should be printed
319 |
# File 'lib/exekutor/configuration.rb', line 319 define_option :quiet, reader: :quiet?, type: [TrueClass, FalseClass], required: true, default: false |
#quiet? ⇒ Boolean
Whether to suppress STDOUT messages
Default value:
false
319 |
# File 'lib/exekutor/configuration.rb', line 319 define_option :quiet, reader: :quiet?, type: [TrueClass, FalseClass], required: true, default: false |
#set_db_connection_name=(value) ⇒ self
Sets whether the DB connection name should be set
119 |
# File 'lib/exekutor/configuration.rb', line 119 define_option :set_db_connection_name, type: [TrueClass, FalseClass], required: true |
#set_db_connection_name? ⇒ Boolean?
Whether the DB connection name should be set. Only affects the listener, unless started from the CLI.
Default value:
false (true when started from the CLI)
119 |
# File 'lib/exekutor/configuration.rb', line 119 define_option :set_db_connection_name, type: [TrueClass, FalseClass], required: true |
#status_server_handler=(value) ⇒ self
Sets the rack handler for the status server. The handler should respond to #shutdown
or #stop
.
264 |
# File 'lib/exekutor/configuration.rb', line 264 define_option :status_server_handler, default: "webrick", type: String |
#status_server_handler? ⇒ String
The rack handler for the status server
Default value:
“webrick”
264 |
# File 'lib/exekutor/configuration.rb', line 264 define_option :status_server_handler, default: "webrick", type: String |
#status_server_port=(value) ⇒ self
Sets the port number for the status server.
276 |
# File 'lib/exekutor/configuration.rb', line 276 define_option :status_server_port, default: nil, type: Integer |
#status_server_port? ⇒ Integer
The port number for the status server
Default value:
nil
(ie. the status server is disabled)
276 |
# File 'lib/exekutor/configuration.rb', line 276 define_option :status_server_port, default: nil, type: Integer |
#worker_options ⇒ Hash
Gets the options for a worker
323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 |
# File 'lib/exekutor/configuration.rb', line 323 def { min_threads: min_execution_threads, max_threads: max_execution_threads, max_thread_idletime: max_execution_thread_idletime.to_f }.tap do |opts| opts[:set_db_connection_name] = set_db_connection_name? unless set_db_connection_name.nil? %i[enable_listener delete_completed_jobs delete_discarded_jobs delete_failed_jobs].each do |option| opts[option] = send(:"#{option}?") ? true : false end %i[polling_interval polling_jitter status_server_handler status_server_port healthcheck_timeout] .each do |option| opts[option] = send(option) end end end |