Class: Conductor::Workflow::Dsl::WorkflowDefinition
- Inherits:
-
Object
- Object
- Conductor::Workflow::Dsl::WorkflowDefinition
- Defined in:
- lib/conductor/workflow/dsl/workflow_definition.rb
Overview
WorkflowDefinition wraps a WorkflowBuilder and provides methods for registering and executing workflows.
Instance Attribute Summary collapse
-
#builder ⇒ Object
readonly
Returns the value of attribute builder.
Instance Method Summary collapse
-
#call(**input) ⇒ WorkflowRun
Execute this workflow (alias for execute).
-
#execute(input: {}, wait_for_seconds: 30, correlation_id: nil, domain: nil, wait_until_task_ref: nil, request_id: nil) ⇒ WorkflowRun
Execute this workflow and wait for completion.
-
#initialize(builder, executor: nil) ⇒ WorkflowDefinition
constructor
A new instance of WorkflowDefinition.
-
#inspect ⇒ String
Inspect the workflow definition.
-
#name ⇒ String
Get the workflow name.
-
#register(overwrite: false) ⇒ Object
Register this workflow with Conductor.
-
#start(input: {}, correlation_id: nil, domain: nil) ⇒ String
Start this workflow asynchronously (returns immediately with workflow ID).
-
#status(workflow_id, include_tasks: true) ⇒ Workflow
Get the workflow status.
-
#to_s ⇒ String
Convert to string.
-
#to_workflow_def ⇒ Conductor::Http::Models::WorkflowDef
Convert to WorkflowDef model.
-
#version ⇒ Integer?
Get the workflow version.
Constructor Details
#initialize(builder, executor: nil) ⇒ WorkflowDefinition
Returns a new instance of WorkflowDefinition.
22 23 24 25 |
# File 'lib/conductor/workflow/dsl/workflow_definition.rb', line 22 def initialize(builder, executor: nil) @builder = builder @executor = executor end |
Instance Attribute Details
#builder ⇒ Object (readonly)
Returns the value of attribute builder.
18 19 20 |
# File 'lib/conductor/workflow/dsl/workflow_definition.rb', line 18 def builder @builder end |
Instance Method Details
#call(**input) ⇒ WorkflowRun
Execute this workflow (alias for execute)
93 94 95 |
# File 'lib/conductor/workflow/dsl/workflow_definition.rb', line 93 def call(**input) execute(input: input) end |
#execute(input: {}, wait_for_seconds: 30, correlation_id: nil, domain: nil, wait_until_task_ref: nil, request_id: nil) ⇒ WorkflowRun
Execute this workflow and wait for completion
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/conductor/workflow/dsl/workflow_definition.rb', line 71 def execute(input: {}, wait_for_seconds: 30, correlation_id: nil, domain: nil, wait_until_task_ref: nil, request_id: nil) raise 'Executor required for execution. Pass executor: option to Conductor.workflow' unless @executor @executor.execute( @builder.name, input: input, version: @builder.version, wait_for_seconds: wait_for_seconds, correlation_id: correlation_id, domain: domain, wait_until_task_ref: wait_until_task_ref, request_id: request_id ) end |
#inspect ⇒ String
Inspect the workflow definition
137 138 139 140 |
# File 'lib/conductor/workflow/dsl/workflow_definition.rb', line 137 def inspect "#<Conductor::Workflow::Dsl::WorkflowDefinition name=#{@builder.name.inspect} " \ "version=#{@builder.version.inspect} tasks=#{@builder.tasks.size}>" end |
#name ⇒ String
Get the workflow name
29 30 31 |
# File 'lib/conductor/workflow/dsl/workflow_definition.rb', line 29 def name @builder.name end |
#register(overwrite: false) ⇒ Object
Register this workflow with Conductor
52 53 54 55 56 |
# File 'lib/conductor/workflow/dsl/workflow_definition.rb', line 52 def register(overwrite: false) raise 'Executor required for registration. Pass executor: option to Conductor.workflow' unless @executor @executor.register_workflow(self, overwrite: overwrite) end |
#start(input: {}, correlation_id: nil, domain: nil) ⇒ String
Start this workflow asynchronously (returns immediately with workflow ID)
106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/conductor/workflow/dsl/workflow_definition.rb', line 106 def start(input: {}, correlation_id: nil, domain: nil) raise 'Executor required for starting workflow. Pass executor: option to Conductor.workflow' unless @executor request = Conductor::Http::Models::StartWorkflowRequest.new( name: @builder.name, version: @builder.version, input: input, correlation_id: correlation_id ) request.task_to_domain = { '*' => domain } if domain @executor.start_workflow(request) end |
#status(workflow_id, include_tasks: true) ⇒ Workflow
Get the workflow status
129 130 131 132 133 |
# File 'lib/conductor/workflow/dsl/workflow_definition.rb', line 129 def status(workflow_id, include_tasks: true) raise 'Executor required for checking status. Pass executor: option to Conductor.workflow' unless @executor @executor.get_workflow(workflow_id, include_tasks: include_tasks) end |
#to_s ⇒ String
Convert to string
144 145 146 |
# File 'lib/conductor/workflow/dsl/workflow_definition.rb', line 144 def to_s "#{@builder.name}:#{@builder.version || 'latest'}" end |
#to_workflow_def ⇒ Conductor::Http::Models::WorkflowDef
Convert to WorkflowDef model
41 42 43 |
# File 'lib/conductor/workflow/dsl/workflow_definition.rb', line 41 def to_workflow_def @builder.to_workflow_def end |
#version ⇒ Integer?
Get the workflow version
35 36 37 |
# File 'lib/conductor/workflow/dsl/workflow_definition.rb', line 35 def version @builder.version end |