Class: Aidp::Temporal::Worker
- Inherits:
-
Object
- Object
- Aidp::Temporal::Worker
- Defined in:
- lib/aidp/temporal/worker.rb
Overview
Temporal worker that runs workflows and activities Manages the worker lifecycle and task queue configuration
Constant Summary collapse
- DEFAULT_TASK_QUEUE =
"aidp-workflows"- DEFAULT_MAX_CONCURRENT_ACTIVITIES =
10- DEFAULT_MAX_CONCURRENT_WORKFLOWS =
10
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
-
#task_queue ⇒ Object
readonly
Returns the value of attribute task_queue.
Instance Method Summary collapse
-
#initialize(connection:, config: {}) ⇒ Worker
constructor
A new instance of Worker.
-
#register_activities(*activity_classes) ⇒ Object
Register activity classes or instances.
-
#register_workflows(*workflow_classes) ⇒ Object
Register workflow classes.
-
#run ⇒ Object
Start the worker (blocking).
-
#running? ⇒ Boolean
Check if running.
-
#shutdown ⇒ Object
Request graceful shutdown.
-
#shutdown_requested? ⇒ Boolean
Check if shutdown was requested.
Constructor Details
#initialize(connection:, config: {}) ⇒ Worker
Returns a new instance of Worker.
17 18 19 20 21 22 23 24 |
# File 'lib/aidp/temporal/worker.rb', line 17 def initialize(connection:, config: {}) @connection = connection @config = normalize_config(config) @task_queue = @config[:task_queue] @worker = nil @running = false @shutdown_requested = false end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
15 16 17 |
# File 'lib/aidp/temporal/worker.rb', line 15 def config @config end |
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
15 16 17 |
# File 'lib/aidp/temporal/worker.rb', line 15 def connection @connection end |
#task_queue ⇒ Object (readonly)
Returns the value of attribute task_queue.
15 16 17 |
# File 'lib/aidp/temporal/worker.rb', line 15 def task_queue @task_queue end |
Instance Method Details
#register_activities(*activity_classes) ⇒ Object
Register activity classes or instances
34 35 36 37 38 |
# File 'lib/aidp/temporal/worker.rb', line 34 def register_activities(*activity_classes) @activity_classes ||= [] @activity_classes.concat(activity_classes) self end |
#register_workflows(*workflow_classes) ⇒ Object
Register workflow classes
27 28 29 30 31 |
# File 'lib/aidp/temporal/worker.rb', line 27 def register_workflows(*workflow_classes) @workflow_classes ||= [] @workflow_classes.concat(workflow_classes) self end |
#run ⇒ Object
Start the worker (blocking)
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/aidp/temporal/worker.rb', line 41 def run return if @running Aidp.log_info("temporal_worker", "starting", task_queue: @task_queue, workflows: @workflow_classes&.map(&:name), activities: @activity_classes&.map { |a| a.is_a?(Class) ? a.name : a.class.name }) @running = true @shutdown_requested = false begin @worker = create_worker @worker.run rescue => e Aidp.log_error("temporal_worker", "run_failed", error: e., error_class: e.class.name) raise ensure @running = false @worker = nil end end |
#running? ⇒ Boolean
Check if running
76 77 78 |
# File 'lib/aidp/temporal/worker.rb', line 76 def running? @running end |
#shutdown ⇒ Object
Request graceful shutdown
67 68 69 70 71 72 73 |
# File 'lib/aidp/temporal/worker.rb', line 67 def shutdown return unless @running Aidp.log_info("temporal_worker", "shutdown_requested", task_queue: @task_queue) @shutdown_requested = true @worker&.shutdown end |
#shutdown_requested? ⇒ Boolean
Check if shutdown was requested
81 82 83 |
# File 'lib/aidp/temporal/worker.rb', line 81 def shutdown_requested? @shutdown_requested end |