Class: GenevaDrive::StepDefinition Private

Inherits:
Object
  • Object
show all
Defined in:
lib/geneva_drive/step_definition.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Metadata about a step definition in a workflow. Holds the step name, callable (block or method name), wait time, job options, skip conditions, and exception handling configuration.

Constant Summary collapse

EXCEPTION_HANDLERS =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Valid exception handler values

%i[pause! cancel! reattempt! skip!].freeze
NOT_SET =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Sentinel value to distinguish "on_exception not provided" from "on_exception: :pause!"

Object.new.freeze
VALID_SKIP_CONDITION_TYPES =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Valid types for skip conditions

[Symbol, Proc, TrueClass, FalseClass, NilClass].freeze
DURATION_SHAPED_TYPES =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Types that mean "a delay" and therefore belong to wait:, never wait_for:. ActiveSupport::Duration is a Numeric-alike but not a Numeric, hence both.

[ActiveSupport::Duration, Numeric, Time, Date].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, callable:, call_location: nil, block_location: nil, **options) ⇒ StepDefinition

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Creates a new step definition.

Parameters:

  • name (String, Symbol) —

    the step name

  • callable (Proc, Symbol, nil) —

    the code to execute (block or method name)

  • options (Hash) —

    additional options

  • call_location (Array<String, Integer>, nil) (defaults to: nil) —

    source location where step was called

  • block_location (Array<String, Integer>, nil) (defaults to: nil) —

    source location of the step block

Options Hash (**options):

  • :wait (ActiveSupport::Duration, nil) —

    delay before execution

  • :job_options (Hash) —

    options passed to Active Job's set method

  • :skip_if (Proc, Symbol, Boolean, nil) —

    condition for skipping

  • :if (Proc, Symbol, Boolean, nil) —

    condition for running (inverse of skip_if)

  • :on_exception (Symbol, GenevaDrive::ExceptionPolicy, Proc, Array<GenevaDrive::ExceptionPolicy>) —

    how to handle exceptions. An Array of ExceptionPolicy objects is wrapped in a CombinedExceptionPolicy that resolves specific policies first, then blanket fallback.

  • :max_reattempts (Integer, nil) —

    max consecutive reattempts (symbol form only)

  • :before_step (String, Symbol, nil) —

    position before this step

  • :after_step (String, Symbol, nil) —

    position after this step

Raises:



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/geneva_drive/step_definition.rb', line 76

def initialize(name:, callable:, call_location: nil, block_location: nil, **options)
  @name = name.to_s
  @callable = callable
  @call_location = call_location
  @block_location = block_location
  @wait = options[:wait]
  @wait_for = options[:wait_for]
  @job_options = options.fetch(:job_options, {})
  @skip_if_option = options[:skip_if]
  @if_option = options[:if]
  @skip_condition = @skip_if_option || @if_option
  @on_exception_raw = options.fetch(:on_exception, NOT_SET)
  @max_reattempts_raw = options[:max_reattempts]
  @max_reattempts_explicitly_set = options.key?(:max_reattempts)
  @terminal_action_raw = options[:terminal_action]
  @before_step = options[:before_step]&.to_s
  @after_step = options[:after_step]&.to_s

  validate!
  @job_options = GenevaDrive::JobOptions.validate!(@job_options, context: "Step '#{@name}'").freeze
  @exception_policy = build_exception_policy
  @signal_matcher = build_signal_matcher
end

Instance Attribute Details

#after_step ⇒ String? (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns name of step this should be placed after.

Returns:

  • (String, nil) —

    name of step this should be placed after



44
45
46
# File 'lib/geneva_drive/step_definition.rb', line 44

def after_step
  @after_step
end

#before_step ⇒ String? (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns name of step this should be placed before.

Returns:

  • (String, nil) —

    name of step this should be placed before



41
42
43
# File 'lib/geneva_drive/step_definition.rb', line 41

def before_step
  @before_step
end

#block_location ⇒ Array<String, Integer>? (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns source location of the step block [path, lineno].

Returns:

  • (Array<String, Integer>, nil) —

    source location of the step block [path, lineno]



50
51
52
# File 'lib/geneva_drive/step_definition.rb', line 50

def block_location
  @block_location
end

#call_location ⇒ Array<String, Integer>? (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns source location where step was called [path, lineno].

Returns:

  • (Array<String, Integer>, nil) —

    source location where step was called [path, lineno]



47
48
49
# File 'lib/geneva_drive/step_definition.rb', line 47

def call_location
  @call_location
end

#callable ⇒ Proc, Symbol (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the callable to execute (block or method name).

Returns:

  • (Proc, Symbol) —

    the callable to execute (block or method name)



26
27
28
# File 'lib/geneva_drive/step_definition.rb', line 26

def callable
  @callable
end

#exception_policy ⇒ GenevaDrive::ExceptionPolicy, GenevaDrive::CombinedExceptionPolicy (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns exception handling policy.

Returns:



38
39
40
# File 'lib/geneva_drive/step_definition.rb', line 38

def exception_policy
  @exception_policy
end

#job_options ⇒ Hash (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns frozen, symbol-keyed Active Job options for this step.

Returns:

  • (Hash) —

    frozen, symbol-keyed Active Job options for this step



32
33
34
# File 'lib/geneva_drive/step_definition.rb', line 32

def job_options
  @job_options
end

#name ⇒ String (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the step name.

Returns:

  • (String) —

    the step name



23
24
25
# File 'lib/geneva_drive/step_definition.rb', line 23

def name
  @name
end

#signal_matcher ⇒ GenevaDrive::SignalMatcher? (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the normalized signal matcher, if this step waits.

Returns:



56
57
58
# File 'lib/geneva_drive/step_definition.rb', line 56

def signal_matcher
  @signal_matcher
end

#skip_condition ⇒ Proc, ... (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns condition for skipping this step.

Returns:

  • (Proc, Symbol, Boolean, nil) —

    condition for skipping this step



35
36
37
# File 'lib/geneva_drive/step_definition.rb', line 35

def skip_condition
  @skip_condition
end

#wait ⇒ ActiveSupport::Duration? (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns wait time before executing this step.

Returns:

  • (ActiveSupport::Duration, nil) —

    wait time before executing this step



29
30
31
# File 'lib/geneva_drive/step_definition.rb', line 29

def wait
  @wait
end

#wait_for ⇒ Symbol, ... (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the raw wait_for: option.

Returns:

  • (Symbol, String, Object, nil) —

    the raw wait_for: option



53
54
55
# File 'lib/geneva_drive/step_definition.rb', line 53

def wait_for
  @wait_for
end

Instance Method Details

#execute_in_context(workflow) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Executes the step callable in the context of the workflow.

Parameters:

Returns:

  • (Object) —

    the result of the step execution



154
155
156
157
158
159
160
# File 'lib/geneva_drive/step_definition.rb', line 154

def execute_in_context(workflow)
  if @callable.is_a?(Symbol)
    workflow.send(@callable)
  else
    workflow.instance_exec(&@callable)
  end
end

#max_reattempts ⇒ Integer?

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the max_reattempts from the exception policy. Provided for backward compatibility with code that reads step_def.max_reattempts.

Returns:

  • (Integer, nil)


114
115
116
# File 'lib/geneva_drive/step_definition.rb', line 114

def max_reattempts
  @exception_policy&.max_reattempts
end

#on_exception ⇒ Symbol?

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the action symbol from the exception policy. Provided for backward compatibility with code that reads step_def.on_exception.

Returns:

  • (Symbol, nil) —

    the action symbol, or nil for imperative/combined policies



104
105
106
107
108
# File 'lib/geneva_drive/step_definition.rb', line 104

def on_exception
  return nil unless @exception_policy
  return nil if @exception_policy.is_a?(GenevaDrive::CombinedExceptionPolicy)
  @exception_policy.action
end

#removed? ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns whether this step is a gravestone left by removed_step. Removed steps keep their name resolvable for executions scheduled before the step was taken out, but are never scheduled and never run.

Returns:

  • (Boolean) —

    false for standard steps



139
140
141
# File 'lib/geneva_drive/step_definition.rb', line 139

def removed?
  false
end

#resumable? ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns whether this is a resumable step.

Returns:

  • (Boolean) —

    false for standard steps



130
131
132
# File 'lib/geneva_drive/step_definition.rb', line 130

def resumable?
  false
end

#should_skip?(workflow) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Evaluates whether this step should be skipped for the given workflow.

Parameters:

Returns:

  • (Boolean) —

    true if the step should be skipped



122
123
124
125
# File 'lib/geneva_drive/step_definition.rb', line 122

def should_skip?(workflow)
  return false unless @skip_condition
  evaluate_condition(@skip_condition, workflow)
end

#waits_for_signal? ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Whether this step parks until a matching signal arrives.

Returns:

  • (Boolean)


146
147
148
# File 'lib/geneva_drive/step_definition.rb', line 146

def waits_for_signal?
  !@signal_matcher.nil?
end