@@ -16,6 +16,59 @@ use std::{
1616 time:: Duration ,
1717} ;
1818
19+ /// Specifies which task types a worker will poll for.
20+ ///
21+ /// Workers can be configured to handle any combination of workflows, activities, and nexus operations.
22+ #[ derive( Clone , Copy , Debug , PartialEq , Eq , Hash ) ]
23+ pub struct WorkerTaskTypes {
24+ pub enable_workflows : bool ,
25+ pub enable_activities : bool ,
26+ pub enable_nexus : bool ,
27+ }
28+
29+ impl WorkerTaskTypes {
30+ /// Check if no task types are enabled
31+ pub fn is_empty ( & self ) -> bool {
32+ !self . enable_workflows && !self . enable_activities && !self . enable_nexus
33+ }
34+
35+ /// Create a config with all task types enabled
36+ pub fn all ( ) -> WorkerTaskTypes {
37+ WorkerTaskTypes {
38+ enable_workflows : true ,
39+ enable_activities : true ,
40+ enable_nexus : true ,
41+ }
42+ }
43+
44+ /// Create a config with only workflow tasks enabled
45+ pub fn workflow_only ( ) -> WorkerTaskTypes {
46+ WorkerTaskTypes {
47+ enable_workflows : true ,
48+ enable_activities : false ,
49+ enable_nexus : false ,
50+ }
51+ }
52+
53+ /// Create a config with only activity tasks enabled
54+ pub fn activity_only ( ) -> WorkerTaskTypes {
55+ WorkerTaskTypes {
56+ enable_workflows : false ,
57+ enable_activities : true ,
58+ enable_nexus : false ,
59+ }
60+ }
61+
62+ /// Create a config with only nexus tasks enabled
63+ pub fn nexus_only ( ) -> WorkerTaskTypes {
64+ WorkerTaskTypes {
65+ enable_workflows : false ,
66+ enable_activities : false ,
67+ enable_nexus : true ,
68+ }
69+ }
70+ }
71+
1972/// Defines per-worker configuration options
2073#[ derive( Clone , derive_builder:: Builder ) ]
2174#[ builder( setter( into) , build_fn( validate = "Self::validate" ) ) ]
@@ -64,10 +117,10 @@ pub struct WorkerConfig {
64117 /// worker's task queue
65118 #[ builder( default = "PollerBehavior::SimpleMaximum(5)" ) ]
66119 pub nexus_task_poller_behavior : PollerBehavior ,
67- /// If set to true this worker will only handle workflow tasks and local activities, it will not
68- /// poll for activity tasks.
69- # [ builder ( default = "false" ) ]
70- pub no_remote_activities : bool ,
120+ /// Specifies which task types this worker will poll for.
121+ ///
122+ /// Note: At least one task type must be specified or the worker will fail validation.
123+ pub task_types : WorkerTaskTypes ,
71124 /// How long a workflow task is allowed to sit on the sticky queue before it is timed out
72125 /// and moved to the non-sticky queue where it may be picked up by any worker.
73126 #[ builder( default = "Duration::from_secs(10)" ) ]
@@ -218,6 +271,15 @@ impl WorkerConfigBuilder {
218271 }
219272
220273 fn validate ( & self ) -> Result < ( ) , String > {
274+ let task_types = self
275+ . task_types
276+ . as_ref ( )
277+ . cloned ( )
278+ . unwrap_or_else ( WorkerTaskTypes :: all) ;
279+ if task_types. is_empty ( ) {
280+ return Err ( "At least one task type must be enabled in `task_types`" . to_owned ( ) ) ;
281+ }
282+
221283 if let Some ( b) = self . workflow_task_poller_behavior . as_ref ( ) {
222284 b. validate ( ) ?
223285 }
@@ -249,6 +311,17 @@ impl WorkerConfigBuilder {
249311 return Err ( "`max_outstanding_nexus_tasks` must be > 0" . to_owned ( ) ) ;
250312 }
251313
314+ // Validate workflow cache is consistent with task_types
315+ if !task_types. enable_workflows
316+ && let Some ( cache) = self . max_cached_workflows . as_ref ( )
317+ && * cache > 0
318+ {
319+ return Err (
320+ "Cannot have `max_cached_workflows` > 0 when workflows are not enabled in `task_types`"
321+ . to_owned ( ) ,
322+ ) ;
323+ }
324+
252325 if let Some ( cache) = self . max_cached_workflows . as_ref ( )
253326 && * cache > 0
254327 {
0 commit comments