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
   exekutor_options 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

Class Method Summary collapse

Instance Attribute Details

#exekutor_optionsHash<Symbol, Object> (readonly)

Returns the exekutor options for this job.

Returns:

  • (Hash<Symbol, Object>)

    the exekutor options for this job



40
41
42
# File 'lib/exekutor/job_options.rb', line 40

def exekutor_options
  @exekutor_options
end

Class Method Details

.validate_option_type!(options, name, valid_type) ⇒ Object

Validates the type of an option

Parameters:

  • options (Hash<Symbol, Any>)

    the options

  • name (Symbol)

    the name of the option to validate

  • valid_type (Class)

    the valid type for the value

Raises:

  • (InvalidOption)

    if the configured value is not an instance of valid_type



95
96
97
98
99
# File 'lib/exekutor/job_options.rb', line 95

def self.validate_option_type!(options, name, valid_type)
  return if options[name].nil? || options[name].is_a?(valid_type)

  raise InvalidOption, ":#{name} must be an instance of #{valid_type.name} (given: #{options[name].class.name})"
end