Module: ActiveJob::Temporal::DependencyOptions

Defined in:
lib/activejob/temporal/dependency_options.rb

Constant Summary collapse

JOB_CLASS_NAME_PATTERN =
/\A[A-Z]\w*(?:::[A-Z]\w*)*\z/
SAFE_ID_PATTERN =
/\A[A-Za-z0-9_.:-]+\z/
FAILURE_POLICIES =
%i[fail ignore].freeze
WAIT_OPTION_KEYS =
%i[timeout initial_interval max_interval backoff].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#temporal_dependenciesObject (readonly)

Returns the value of attribute temporal_dependencies.



14
15
16
# File 'lib/activejob/temporal/dependency_options.rb', line 14

def temporal_dependencies
  @temporal_dependencies
end

#temporal_dependency_failure_policyObject (readonly)

Returns the value of attribute temporal_dependency_failure_policy.



14
15
16
# File 'lib/activejob/temporal/dependency_options.rb', line 14

def temporal_dependency_failure_policy
  @temporal_dependency_failure_policy
end

#temporal_dependency_waitObject (readonly)

Returns the value of attribute temporal_dependency_wait.



14
15
16
# File 'lib/activejob/temporal/dependency_options.rb', line 14

def temporal_dependency_wait
  @temporal_dependency_wait
end

Class Method Details

.normalize(depends_on) ⇒ Object

Raises:

  • (ArgumentError)


16
17
18
19
20
21
# File 'lib/activejob/temporal/dependency_options.rb', line 16

def self.normalize(depends_on)
  dependencies = depends_on.is_a?(Array) ? depends_on : [depends_on]
  raise ArgumentError, "depends_on must contain at least one job dependency" if dependencies.empty?

  dependencies.map { |dependency| normalize_dependency(dependency) }
end

.normalize_failure_policy(policy) ⇒ Object



23
24
25
26
27
28
29
30
# File 'lib/activejob/temporal/dependency_options.rb', line 23

def self.normalize_failure_policy(policy)
  normalized_policy = policy.to_sym
  return normalized_policy if FAILURE_POLICIES.include?(normalized_policy)

  raise ArgumentError, "on_dependency_failure must be :fail or :ignore"
rescue NoMethodError
  raise ArgumentError, "on_dependency_failure must be :fail or :ignore"
end

.normalize_wait_options(options) ⇒ Object

Raises:

  • (ArgumentError)


32
33
34
35
36
37
38
39
40
41
# File 'lib/activejob/temporal/dependency_options.rb', line 32

def self.normalize_wait_options(options)
  raise ArgumentError, "dependency_wait must be a hash" unless options.is_a?(Hash)

  normalized = options.each_with_object({}) do |(key, value), wait_options|
    normalized_key = normalize_wait_option_key(key)
    wait_options[normalized_key] = normalize_wait_option_value(normalized_key, value)
  end
  validate_wait_interval_order!(normalized)
  normalized
end

Instance Method Details

#set(options = {}) ⇒ Object



163
164
165
166
167
168
169
170
171
# File 'lib/activejob/temporal/dependency_options.rb', line 163

def set(options = {})
  enqueue_options = options.dup
  dependency_options = normalize_dependency_set_options(enqueue_options)
  validate_dependency_set_options!(dependency_options)

  super(enqueue_options).tap do
    apply_dependency_set_options(dependency_options)
  end
end