Class: Hatchet::TaskRunRef

Inherits:
Object
  • Object
show all
Defined in:
lib/hatchet/workflow_run.rb

Overview

Reference to a running standalone task, returned by ‘Task#run_no_wait`.

Wraps a WorkflowRunRef and automatically extracts the task-specific output from the workflow-level result. For a task named “my_task”, calling result returns the task output directly (e.g. ‘=> 42`) instead of the full keyed output (`=> {“value” => 42}`).

Examples:

ref = my_task.run_no_wait(input)
output = ref.result  # => {"value" => 42}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(workflow_run_ref:, task_name:) ⇒ TaskRunRef

Returns a new instance of TaskRunRef.

Parameters:

  • workflow_run_ref (WorkflowRunRef)

    The underlying workflow run reference

  • task_name (Symbol, String)

    The task name used to extract output



112
113
114
115
116
# File 'lib/hatchet/workflow_run.rb', line 112

def initialize(workflow_run_ref:, task_name:)
  @workflow_run_ref = workflow_run_ref
  @task_name = task_name.to_s
  @workflow_run_id = workflow_run_ref.workflow_run_id
end

Instance Attribute Details

#workflow_run_idString (readonly)

Returns The workflow run ID.

Returns:

  • (String)

    The workflow run ID



108
109
110
# File 'lib/hatchet/workflow_run.rb', line 108

def workflow_run_id
  @workflow_run_id
end

Instance Method Details

#resultHash

Block until the task completes and return the extracted task output

Returns:

  • (Hash)

    The task output

Raises:



122
123
124
125
126
127
# File 'lib/hatchet/workflow_run.rb', line 122

def result
  full_result = @workflow_run_ref.result
  return full_result unless full_result.is_a?(Hash)

  full_result[@task_name] || full_result
end