Class: Conductor::Workflow::Dsl::TaskRef

Inherits:
Object
  • Object
show all
Defined in:
lib/conductor/workflow/dsl/task_ref.rb

Overview

TaskRef is a lightweight proxy returned by DSL task methods Enables [] syntax for output references and stores task metadata

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ref_name:, task_name:, task_type:, input_parameters: {}, options: {}) ⇒ TaskRef

Returns a new instance of TaskRef.

Parameters:

  • ref_name (String)

    Auto-generated reference name

  • task_name (String)

    The task definition name

  • task_type (String)

    Conductor task type (SIMPLE, HTTP, etc.)

  • input_parameters (Hash) (defaults to: {})

    Input parameters for the task

  • options (Hash) (defaults to: {})

    Additional options (optional, cache, retry, etc.)



17
18
19
20
21
22
23
# File 'lib/conductor/workflow/dsl/task_ref.rb', line 17

def initialize(ref_name:, task_name:, task_type:, input_parameters: {}, options: {})
  @ref_name = ref_name
  @task_name = task_name
  @task_type = task_type
  @input_parameters = input_parameters
  @options = options
end

Instance Attribute Details

#input_parametersObject (readonly) Also known as: inputs

Returns the value of attribute input_parameters.



9
10
11
# File 'lib/conductor/workflow/dsl/task_ref.rb', line 9

def input_parameters
  @input_parameters
end

#optionsObject (readonly)

Returns the value of attribute options.



9
10
11
# File 'lib/conductor/workflow/dsl/task_ref.rb', line 9

def options
  @options
end

#ref_nameObject (readonly)

Returns the value of attribute ref_name.



9
10
11
# File 'lib/conductor/workflow/dsl/task_ref.rb', line 9

def ref_name
  @ref_name
end

#task_nameObject (readonly)

Returns the value of attribute task_name.



9
10
11
# File 'lib/conductor/workflow/dsl/task_ref.rb', line 9

def task_name
  @task_name
end

#task_typeObject (readonly)

Returns the value of attribute task_type.



9
10
11
# File 'lib/conductor/workflow/dsl/task_ref.rb', line 9

def task_type
  @task_type
end

Instance Method Details

#[](field) ⇒ OutputRef

Access task output by field name using [] syntax

Examples:

user = simple :get_user, id: 1
user[:email] # => "${get_user_ref.output.email}"
user[:profile][:name] # => "${get_user_ref.output.profile.name}"

Parameters:

  • field (String, Symbol)

    The output field name

Returns:

  • (OutputRef)

    An OutputRef pointing to this task's output



32
33
34
# File 'lib/conductor/workflow/dsl/task_ref.rb', line 32

def [](field)
  OutputRef.new("#{@ref_name}.output.#{field}")
end

#input(field = nil) ⇒ OutputRef

Access task input (for dynamic references)

Parameters:

  • field (String, Symbol, nil) (defaults to: nil)

    Optional field name

Returns:

  • (OutputRef)

    An OutputRef pointing to task input



45
46
47
48
49
50
51
# File 'lib/conductor/workflow/dsl/task_ref.rb', line 45

def input(field = nil)
  if field
    OutputRef.new("#{@ref_name}.input.#{field}")
  else
    OutputRef.new("#{@ref_name}.input")
  end
end

#outputOutputRef

Access task's full output (no specific field)

Returns:

  • (OutputRef)

    An OutputRef pointing to all task output



38
39
40
# File 'lib/conductor/workflow/dsl/task_ref.rb', line 38

def output
  OutputRef.new("#{@ref_name}.output")
end

#to_workflow_taskConductor::Http::Models::WorkflowTask

Convert to WorkflowTask model for serialization



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/conductor/workflow/dsl/task_ref.rb', line 55

def to_workflow_task
  wf_task = Conductor::Http::Models::WorkflowTask.new(
    name: @task_name,
    task_reference_name: @ref_name,
    type: @task_type,
    input_parameters: @input_parameters
  )

  # Apply options
  wf_task.description = @options[:description] if @options[:description]
  wf_task.optional = @options[:optional] if @options[:optional]

  # Cache config
  if @options[:cache_key] && @options[:cache_ttl]
    wf_task.cache_config = Conductor::Http::Models::CacheConfig.new(
      key: @options[:cache_key],
      ttl_in_second: @options[:cache_ttl]
    )
  end

  # Task-specific fields
  apply_task_specific_fields(wf_task)

  wf_task
end