Class: GenevaDrive::Executor Private

Inherits:
Object
  • Object
show all
Defined in:
lib/geneva_drive/executor.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.

Executes a single step within a workflow context. Handles flow control signals, exception handling, and state transitions.

The Executor owns the step execution and workflow during execution, using pessimistic locking to ensure atomicity of state transitions.

Execution phases:

  1. Acquire locks, validate states, transition to executing/performing
  2. Release locks, execute user code (step block)
  3. Acquire locks, handle flow control result, transition to final states

Constant Summary collapse

STEP_TRANSITIONS =

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 state transitions for step executions

{
  "scheduled" => %w[scheduled in_progress canceled skipped failed completed],
  "in_progress" => %w[in_progress completed failed canceled skipped]
}.freeze
WORKFLOW_TRANSITIONS =

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 state transitions for workflows

{
  "ready" => %w[ready performing canceled paused finished],
  "performing" => %w[ready performing canceled paused finished]
}.freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.execute!(step_execution, logger: nil) ⇒ void

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.

This method returns an undefined value.

Executes a step execution with full flow control and exception handling.

Examples:

Execute with a pre-tagged logger from a background job

logger = Rails.logger.tagged("job_id=#{job_id}")
GenevaDrive::Executor.execute!(step_execution, logger: logger)

Parameters:

  • step_execution (GenevaDrive::StepExecution)

    the step to execute

  • logger (Logger, nil) (defaults to: nil)

    optional base logger to inject into the workflow. If provided, this logger will be used as the base for all workflow logging, with workflow and step-specific tags added on top. This allows callers (background jobs, controllers, etc.) to pass in a logger that already has appropriate context tags (e.g., job_id, request_id).



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

def self.execute!(step_execution, logger: nil)
  new.call(step_execution, logger: logger)
end

Instance Method Details

#call(step_execution, logger: nil) ⇒ void

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.

This method returns an undefined value.

Performs the step execution.

Parameters:

  • step_execution (GenevaDrive::StepExecution)

    the step to execute

  • logger (Logger, nil) (defaults to: nil)

    optional base logger to inject into the workflow



50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/geneva_drive/executor.rb', line 50

def call(step_execution, logger: nil)
  @step_execution = step_execution
  @workflow = step_execution.workflow

  # Build the full logger chain (base -> workflow -> step tags) and inject
  # it so step code calling `logger` gets the fully-tagged step execution
  # logger. Falls back to Rails.logger if no logger is provided.
  step_logger = build_step_logger(logger || Rails.logger, step_execution)
  @workflow.with_logger(step_logger) do
    step_execution.with_logger(step_logger) do
      execute_with_logger(step_execution)
    end
  end
end