Class: Conductor::Worker::TaskContext
- Inherits:
-
Object
- Object
- Conductor::Worker::TaskContext
- Defined in:
- lib/conductor/worker/task_context.rb
Overview
Provides execution context for workers Accessible from anywhere in worker code via TaskContext.current Stored in thread-local storage (Thread.current)
Instance Attribute Summary collapse
-
#task ⇒ Task
readonly
The task being executed.
-
#task_result ⇒ TaskResult
readonly
The task result being built.
Class Method Summary collapse
-
.clear ⇒ void
Clear the current task context (internal use by TaskRunner).
-
.current ⇒ TaskContext?
Get the current task context (thread-local).
-
.current=(context) ⇒ void
Set the current task context (internal use by TaskRunner).
Instance Method Summary collapse
-
#add_log(message) ⇒ void
Add a log message to the task result Logs are visible in the Conductor UI.
-
#callback_after_seconds ⇒ Integer?
Get the callback_after_seconds value.
-
#initialize(task, task_result) ⇒ TaskContext
constructor
Initialize a new task context.
-
#input ⇒ Hash
Get the task input data.
-
#poll_count ⇒ Integer
Get the poll count (how many times this task has been polled for long-running tasks).
-
#retry_count ⇒ Integer
Get the retry count (how many times this task has been retried).
-
#set_callback_after(seconds) ⇒ void
Set the callback_after_seconds for long-running tasks When returning TaskInProgress, this determines when Conductor will poll again.
-
#set_output(output_data) ⇒ void
Set the output data on the task result.
-
#task_def_name ⇒ String
Get the task definition name.
-
#task_id ⇒ String
Get the task ID.
-
#workflow_instance_id ⇒ String
Get the workflow instance ID.
-
#workflow_task_type ⇒ String
Get the workflow task type.
Constructor Details
#initialize(task, task_result) ⇒ TaskContext
Initialize a new task context
37 38 39 40 |
# File 'lib/conductor/worker/task_context.rb', line 37 def initialize(task, task_result) @task = task @task_result = task_result end |
Instance Attribute Details
#task ⇒ Task (readonly)
Returns The task being executed.
10 11 12 |
# File 'lib/conductor/worker/task_context.rb', line 10 def task @task end |
#task_result ⇒ TaskResult (readonly)
Returns The task result being built.
13 14 15 |
# File 'lib/conductor/worker/task_context.rb', line 13 def task_result @task_result end |
Class Method Details
.clear ⇒ void
This method returns an undefined value.
Clear the current task context (internal use by TaskRunner)
30 31 32 |
# File 'lib/conductor/worker/task_context.rb', line 30 def self.clear Thread.current[:conductor_task_context] = nil end |
.current ⇒ TaskContext?
Get the current task context (thread-local)
17 18 19 |
# File 'lib/conductor/worker/task_context.rb', line 17 def self.current Thread.current[:conductor_task_context] end |
.current=(context) ⇒ void
This method returns an undefined value.
Set the current task context (internal use by TaskRunner)
24 25 26 |
# File 'lib/conductor/worker/task_context.rb', line 24 def self.current=(context) Thread.current[:conductor_task_context] = context end |
Instance Method Details
#add_log(message) ⇒ void
This method returns an undefined value.
Add a log message to the task result Logs are visible in the Conductor UI
88 89 90 |
# File 'lib/conductor/worker/task_context.rb', line 88 def add_log() @task_result.log() end |
#callback_after_seconds ⇒ Integer?
Get the callback_after_seconds value
102 103 104 |
# File 'lib/conductor/worker/task_context.rb', line 102 def callback_after_seconds @task_result.callback_after_seconds end |
#input ⇒ Hash
Get the task input data
68 69 70 |
# File 'lib/conductor/worker/task_context.rb', line 68 def input @task.input_data || {} end |
#poll_count ⇒ Integer
Get the poll count (how many times this task has been polled for long-running tasks)
62 63 64 |
# File 'lib/conductor/worker/task_context.rb', line 62 def poll_count @task.poll_count || 0 end |
#retry_count ⇒ Integer
Get the retry count (how many times this task has been retried)
56 57 58 |
# File 'lib/conductor/worker/task_context.rb', line 56 def retry_count @task.retry_count || 0 end |
#set_callback_after(seconds) ⇒ void
This method returns an undefined value.
Set the callback_after_seconds for long-running tasks When returning TaskInProgress, this determines when Conductor will poll again
96 97 98 |
# File 'lib/conductor/worker/task_context.rb', line 96 def set_callback_after(seconds) @task_result.callback_after_seconds = seconds end |
#set_output(output_data) ⇒ void
This method returns an undefined value.
Set the output data on the task result
109 110 111 |
# File 'lib/conductor/worker/task_context.rb', line 109 def set_output(output_data) @task_result.output_data = output_data end |
#task_def_name ⇒ String
Get the task definition name
74 75 76 |
# File 'lib/conductor/worker/task_context.rb', line 74 def task_def_name @task.task_def_name || @task.task_type end |
#task_id ⇒ String
Get the task ID
44 45 46 |
# File 'lib/conductor/worker/task_context.rb', line 44 def task_id @task.task_id end |
#workflow_instance_id ⇒ String
Get the workflow instance ID
50 51 52 |
# File 'lib/conductor/worker/task_context.rb', line 50 def workflow_instance_id @task.workflow_instance_id end |
#workflow_task_type ⇒ String
Get the workflow task type
80 81 82 |
# File 'lib/conductor/worker/task_context.rb', line 80 def workflow_task_type @task.workflow_task&.type || @task.task_type end |