Class: GenevaDrive::StepDefinition Private
- Inherits:
-
Object
- Object
- GenevaDrive::StepDefinition
- 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.
Direct Known Subclasses
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
-
#after_step ⇒ String?
readonly
private
Name of step this should be placed after.
-
#before_step ⇒ String?
readonly
private
Name of step this should be placed before.
-
#block_location ⇒ Array<String, Integer>?
readonly
private
Source location of the step block [path, lineno].
-
#call_location ⇒ Array<String, Integer>?
readonly
private
Source location where step was called [path, lineno].
-
#callable ⇒ Proc, Symbol
readonly
private
The callable to execute (block or method name).
-
#exception_policy ⇒ GenevaDrive::ExceptionPolicy, GenevaDrive::CombinedExceptionPolicy
readonly
private
Exception handling policy.
-
#job_options ⇒ Hash
readonly
private
Frozen, symbol-keyed Active Job options for this step.
-
#name ⇒ String
readonly
private
The step name.
-
#signal_matcher ⇒ GenevaDrive::SignalMatcher?
readonly
private
The normalized signal matcher, if this step waits.
-
#skip_condition ⇒ Proc, ...
readonly
private
Condition for skipping this step.
-
#wait ⇒ ActiveSupport::Duration?
readonly
private
Wait time before executing this step.
-
#wait_for ⇒ Symbol, ...
readonly
private
The raw wait_for: option.
Instance Method Summary collapse
-
#execute_in_context(workflow) ⇒ Object
private
Executes the step callable in the context of the workflow.
-
#initialize(name:, callable:, call_location: nil, block_location: nil, **options) ⇒ StepDefinition
constructor
private
Creates a new step definition.
-
#max_reattempts ⇒ Integer?
private
Returns the max_reattempts from the exception policy.
-
#on_exception ⇒ Symbol?
private
Returns the action symbol from the exception policy.
-
#removed? ⇒ Boolean
private
Returns whether this step is a gravestone left by
removed_step. -
#resumable? ⇒ Boolean
private
Returns whether this is a resumable step.
-
#should_skip?(workflow) ⇒ Boolean
private
Evaluates whether this step should be skipped for the given workflow.
-
#waits_for_signal? ⇒ Boolean
private
Whether this step parks until a matching signal arrives.
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.
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, **) @name = name.to_s @callable = callable @call_location = call_location @block_location = block_location @wait = [:wait] @wait_for = [:wait_for] @job_options = .fetch(:job_options, {}) @skip_if_option = [:skip_if] @if_option = [:if] @skip_condition = @skip_if_option || @if_option @on_exception_raw = .fetch(:on_exception, NOT_SET) @max_reattempts_raw = [:max_reattempts] @max_reattempts_explicitly_set = .key?(:max_reattempts) @terminal_action_raw = [:terminal_action] @before_step = [:before_step]&.to_s @after_step = [: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.
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.
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].
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].
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).
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.
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.
32 33 34 |
# File 'lib/geneva_drive/step_definition.rb', line 32 def @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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
146 147 148 |
# File 'lib/geneva_drive/step_definition.rb', line 146 def waits_for_signal? !@signal_matcher.nil? end |