Module: Exekutor::JobOptions
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/exekutor/job_options.rb
Overview
Mixin which defines custom job options for Exekutor. This module should be included in your job class. You can define the following options after including this module:
Queue timeout
MyJob.set(queue_timeout: 1.hour).perform_later
How long the job is allowed to be in the queue. If a job is not performed before this timeout, it will be discarded. The value should be a ActiveSupport::Duration
.
Execution timeout
MyJob.set(execution_timeout: 1.minute).perform_later
How long the job is allowed to run. If a job is taking longer than this timeout, it will be killed and discarded. The value should be a ActiveSupport::Duration
. Be aware that Timeout::timeout
is used internally for this, which can raise an error at any line of code in your application. Use with caution
Usage
#set
You can specify the options per job when enqueueing the job using #set
.
MyJob.set(option_name: @option_value).perform_later
#exekutor_options
You can also specify options that apply to all instances of a job by calling #exekutor_options.
class MyOtherJob < ActiveJob::Base
include Exekutor::JobOptions
execution_timeout: 10.seconds
end
NB These options only work for jobs that are scheduled with #perform_later
, the options are ignored when you perform the job immediately using #perform_now
.
Defined Under Namespace
Classes: InvalidOption
Instance Attribute Summary collapse
-
#exekutor_options ⇒ Hash<Symbol, Object>
readonly
The exekutor options for this job.
Class Method Summary collapse
-
.validate_option_type!(options, name, valid_type) ⇒ Object
Validates the type of an option.
Instance Attribute Details
#exekutor_options ⇒ Hash<Symbol, Object> (readonly)
Returns the exekutor options for this job.
40 41 42 |
# File 'lib/exekutor/job_options.rb', line 40 def @exekutor_options end |
Class Method Details
.validate_option_type!(options, name, valid_type) ⇒ Object
Validates the type of an option
95 96 97 98 99 |
# File 'lib/exekutor/job_options.rb', line 95 def self.validate_option_type!(, name, valid_type) return if [name].nil? || [name].is_a?(valid_type) raise InvalidOption, ":#{name} must be an instance of #{valid_type.name} (given: #{[name].class.name})" end |