66require 'temporalio/worker/runner'
77require 'temporalio/worker/sync_worker'
88require 'temporalio/worker/thread_pool_executor'
9- require 'temporalio/worker/workflow_worker'
109
1110module Temporalio
12- # Worker to process workflows and/or activities.
11+ # Worker to process activities.
1312 #
1413 # Once created, workers can be run and shutdown explicitly via {#run} and {#shutdown}.
1514 class Worker
@@ -42,13 +41,12 @@ def self.run(*workers, shutdown_signals: [], &block)
4241 Runner . new ( *workers ) . run ( &block )
4342 end
4443
45- # Create a worker to process workflows and/or activities.
44+ # Create a worker to process activities.
4645 #
4746 # @param connection [Temporalio::Connection] A connection to be used for this worker.
4847 # @param namespace [String] A namespace.
4948 # @param task_queue [String] A task queue.
5049 # @param activities [Array<Class>] A list of activities (subclasses of {Temporalio::Activity}).
51- # @param workflows [Array<Class>] A list of workflows (subclasses of {Temporalio::Workflow}).
5250 # @param data_converter [Temporalio::DataConverter] Data converter to use for all data conversions
5351 # to/from payloads.
5452 # @param activity_executor [ThreadPoolExecutor] Concurrent executor for all activities. Defaults
@@ -60,17 +58,15 @@ def self.run(*workers, shutdown_signals: [], &block)
6058 # after a shutdown to complete before they are cancelled. A default value of `nil` means that
6159 # activities are never cancelled when handling a shutdown.
6260 #
63- # @raise [ArgumentError] When no activities or workflows have been provided.
61+ # @raise [ArgumentError] When no activities have been provided.
6462 def initialize (
6563 connection ,
6664 namespace ,
6765 task_queue ,
6866 activities : [ ] ,
69- workflows : [ ] ,
7067 data_converter : Temporalio ::DataConverter . new ,
7168 activity_executor : nil ,
7269 interceptors : [ ] ,
73- max_cached_workflows : 1_000 ,
7470 max_concurrent_activities : 100 ,
7571 graceful_shutdown_timeout : nil
7672 )
@@ -84,7 +80,7 @@ def initialize(
8480 connection . core_connection ,
8581 namespace ,
8682 task_queue ,
87- max_cached_workflows ,
83+ 0 , # maxCachedWorkflows disabled temporarily
8884 # FIXME: expose enable_non_local_activities
8985 activities . empty? ,
9086 )
@@ -101,20 +97,9 @@ def initialize(
10197 graceful_shutdown_timeout ,
10298 )
10399 end
104- @workflow_worker =
105- unless workflows . empty?
106- Worker ::WorkflowWorker . new (
107- namespace ,
108- task_queue ,
109- sync_worker ,
110- workflows ,
111- data_converter ,
112- interceptors ,
113- )
114- end
115100
116- if ! @activity_worker && ! @workflow_worker
117- raise ArgumentError , 'At least one activity or workflow must be specified'
101+ unless @activity_worker
102+ raise ArgumentError , 'At least one activity must be specified'
118103 end
119104 end
120105
@@ -127,9 +112,9 @@ def initialize(
127112 # run it again.
128113 #
129114 # @yield Optionally you can provide a block by the end of which the worker will shut itself
130- # down. You can use this to stop a worker after some time has passed, your workflow has
131- # finished or any other arbitrary implementation has completed. Any errors raised from this
132- # block will be re-raised by this method.
115+ # down. You can use this to stop a worker after some time has passed or any other arbitrary
116+ # implementation has completed. Any errors raised from this block will be re-raised by this
117+ # method.
133118 def run ( &block )
134119 Runner . new ( self ) . run ( &block )
135120 end
@@ -163,8 +148,6 @@ def start(runner = nil)
163148 shutdown ( e ) # initiate shutdown because of a fatal error
164149 end
165150 end
166-
167- task . async { |task | workflow_worker . run ( task ) } if workflow_worker
168151 end
169152 end
170153
@@ -189,8 +172,6 @@ def shutdown(exception = Temporalio::Error::WorkerShutdown.new('Manual shutdown'
189172 activity_worker &.setup_graceful_shutdown_timer ( runtime . reactor )
190173 # Wait for workers to drain any outstanding tasks
191174 activity_worker &.drain
192- workflow_worker &.drain
193- # Stop the executor (at this point there should already be nothing in it)
194175 activity_executor . shutdown
195176 # Finalize the shutdown by stopping the Core
196177 core_worker . finalize_shutdown
@@ -218,6 +199,6 @@ def running?
218199 private
219200
220201 attr_reader :mutex , :runtime , :activity_executor , :core_worker , :activity_worker ,
221- :workflow_worker , : runner
202+ :runner
222203 end
223204end
0 commit comments