Class: Fractor::Workflow::ResultBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/fractor/workflow/execution/result_builder.rb

Overview

Builds the final workflow result from completed jobs and context. Responsible for finding the workflow output and creating the result object.

Instance Method Summary collapse

Constructor Details

#initialize(workflow, context, completed_jobs, failed_jobs, trace: nil) ⇒ ResultBuilder

Initialize the result builder.

Parameters:

  • workflow (Workflow)

    The workflow instance

  • context (WorkflowContext)

    The execution context

  • completed_jobs (Set<String>)

    Set of completed job names

  • failed_jobs (Set<String>)

    Set of failed job names

  • trace (ExecutionTrace, nil) (defaults to: nil)

    Optional execution trace



17
18
19
20
21
22
23
# File 'lib/fractor/workflow/execution/result_builder.rb', line 17

def initialize(workflow, context, completed_jobs, failed_jobs, trace: nil)
  @workflow = workflow
  @context = context
  @completed_jobs = completed_jobs
  @failed_jobs = failed_jobs
  @trace = trace
end

Instance Method Details

#build(start_time, end_time) ⇒ WorkflowResult

Build the workflow result.

Parameters:

  • start_time (Time)

    Workflow start time

  • end_time (Time)

    Workflow end time

Returns:



30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/fractor/workflow/execution/result_builder.rb', line 30

def build(start_time, end_time)
  output = find_workflow_output

  WorkflowResult.new(
    workflow_name: @workflow.class.workflow_name,
    output: output,
    completed_jobs: @completed_jobs.to_a,
    failed_jobs: @failed_jobs.to_a,
    execution_time: end_time - start_time,
    success: @failed_jobs.empty?,
    trace: @trace,
    correlation_id: @context.correlation_id,
  )
end