@@ -277,89 +277,84 @@ impl WorkerConfig {
277277impl < S : worker_config_builder:: IsComplete > WorkerConfigBuilder < S > {
278278 pub fn build ( self ) -> Result < WorkerConfig , String > {
279279 let config = self . build_internal ( ) ;
280+ let task_types = & config. task_types ;
281+ if task_types. is_empty ( ) {
282+ return Err ( "At least one task type must be enabled in `task_types`" . to_string ( ) ) ;
283+ }
284+ if !task_types. enable_workflows && task_types. enable_local_activities {
285+ return Err (
286+ "`task_types` cannot enable local activities without workflows" . to_string ( ) ,
287+ ) ;
288+ }
289+
290+ config. workflow_task_poller_behavior . validate ( ) ?;
291+ config. activity_task_poller_behavior . validate ( ) ?;
292+ config. nexus_task_poller_behavior . validate ( ) ?;
293+
294+ if let Some ( ref x) = config. max_worker_activities_per_second
295+ && ( !x. is_normal ( ) || x. is_sign_negative ( ) )
280296 {
281- let config = config;
282- let task_types = & config. task_types ;
283- if task_types. is_empty ( ) {
284- return Err ( "At least one task type must be enabled in `task_types`" . to_string ( ) ) ;
285- }
286- if !task_types. enable_workflows && task_types. enable_local_activities {
287- return Err (
288- "`task_types` cannot enable local activities without workflows" . to_string ( ) ,
289- ) ;
290- }
297+ return Err (
298+ "`max_worker_activities_per_second` must be positive and nonzero" . to_string ( ) ,
299+ ) ;
300+ }
291301
292- config. workflow_task_poller_behavior . validate ( ) ?;
293- config. activity_task_poller_behavior . validate ( ) ?;
294- config. nexus_task_poller_behavior . validate ( ) ?;
302+ if matches ! ( config. max_outstanding_workflow_tasks, Some ( v) if v == 0 ) {
303+ return Err ( "`max_outstanding_workflow_tasks` must be > 0" . to_string ( ) ) ;
304+ }
305+ if matches ! ( config. max_outstanding_activities, Some ( v) if v == 0 ) {
306+ return Err ( "`max_outstanding_activities` must be > 0" . to_string ( ) ) ;
307+ }
308+ if matches ! ( config. max_outstanding_local_activities, Some ( v) if v == 0 ) {
309+ return Err ( "`max_outstanding_local_activities` must be > 0" . to_string ( ) ) ;
310+ }
311+ if matches ! ( config. max_outstanding_nexus_tasks, Some ( v) if v == 0 ) {
312+ return Err ( "`max_outstanding_nexus_tasks` must be > 0" . to_string ( ) ) ;
313+ }
295314
296- if let Some ( ref x) = config. max_worker_activities_per_second
297- && ( !x. is_normal ( ) || x. is_sign_negative ( ) )
315+ if config. max_cached_workflows > 0 {
316+ if let Some ( max_wft) = config. max_outstanding_workflow_tasks
317+ && max_wft < 2
298318 {
299319 return Err (
300- "`max_worker_activities_per_second` must be positive and nonzero" . to_string ( ) ,
320+ "`max_cached_workflows` > 0 requires `max_outstanding_workflow_tasks` >= 2"
321+ . to_string ( ) ,
301322 ) ;
302323 }
303-
304- if matches ! ( config. max_outstanding_workflow_tasks, Some ( v) if v == 0 ) {
305- return Err ( "`max_outstanding_workflow_tasks` must be > 0" . to_string ( ) ) ;
306- }
307- if matches ! ( config. max_outstanding_activities, Some ( v) if v == 0 ) {
308- return Err ( "`max_outstanding_activities` must be > 0" . to_string ( ) ) ;
309- }
310- if matches ! ( config. max_outstanding_local_activities, Some ( v) if v == 0 ) {
311- return Err ( "`max_outstanding_local_activities` must be > 0" . to_string ( ) ) ;
312- }
313- if matches ! ( config. max_outstanding_nexus_tasks, Some ( v) if v == 0 ) {
314- return Err ( "`max_outstanding_nexus_tasks` must be > 0" . to_string ( ) ) ;
324+ if matches ! ( config. workflow_task_poller_behavior, PollerBehavior :: SimpleMaximum ( u) if u < 2 )
325+ {
326+ return Err ( "`max_cached_workflows` > 0 requires `workflow_task_poller_behavior` to be at least 2" . to_string ( ) ) ;
315327 }
328+ }
316329
317- if config. max_cached_workflows > 0 {
318- if let Some ( max_wft) = config. max_outstanding_workflow_tasks
319- && max_wft < 2
330+ if config. tuner . is_some ( )
331+ && ( config. max_outstanding_workflow_tasks . is_some ( )
332+ || config. max_outstanding_activities . is_some ( )
333+ || config. max_outstanding_local_activities . is_some ( ) )
334+ {
335+ return Err ( "max_outstanding_* fields are mutually exclusive with `tuner`" . to_string ( ) ) ;
336+ }
337+
338+ match & config. versioning_strategy {
339+ WorkerVersioningStrategy :: None { .. } => { }
340+ WorkerVersioningStrategy :: WorkerDeploymentBased ( d) => {
341+ if d. use_worker_versioning
342+ && ( d. version . build_id . is_empty ( ) || d. version . deployment_name . is_empty ( ) )
320343 {
344+ return Err ( "WorkerDeploymentVersion must have a non-empty build_id and deployment_name when deployment-based versioning is enabled" . to_string ( ) ) ;
345+ }
346+ }
347+ WorkerVersioningStrategy :: LegacyBuildIdBased { build_id } => {
348+ if build_id. is_empty ( ) {
321349 return Err (
322- "`max_cached_workflows` > 0 requires `max_outstanding_workflow_tasks` >= 2 "
350+ "Legacy build id-based versioning must have a non-empty build_id "
323351 . to_string ( ) ,
324352 ) ;
325353 }
326- if matches ! ( config. workflow_task_poller_behavior, PollerBehavior :: SimpleMaximum ( u) if u < 2 )
327- {
328- return Err ( "`max_cached_workflows` > 0 requires `workflow_task_poller_behavior` to be at least 2" . to_string ( ) ) ;
329- }
330- }
331-
332- if config. tuner . is_some ( )
333- && ( config. max_outstanding_workflow_tasks . is_some ( )
334- || config. max_outstanding_activities . is_some ( )
335- || config. max_outstanding_local_activities . is_some ( ) )
336- {
337- return Err (
338- "max_outstanding_* fields are mutually exclusive with `tuner`" . to_string ( ) ,
339- ) ;
340- }
341-
342- match & config. versioning_strategy {
343- WorkerVersioningStrategy :: None { .. } => { }
344- WorkerVersioningStrategy :: WorkerDeploymentBased ( d) => {
345- if d. use_worker_versioning
346- && ( d. version . build_id . is_empty ( ) || d. version . deployment_name . is_empty ( ) )
347- {
348- return Err ( "WorkerDeploymentVersion must have a non-empty build_id and deployment_name when deployment-based versioning is enabled" . to_string ( ) ) ;
349- }
350- }
351- WorkerVersioningStrategy :: LegacyBuildIdBased { build_id } => {
352- if build_id. is_empty ( ) {
353- return Err (
354- "Legacy build id-based versioning must have a non-empty build_id"
355- . to_string ( ) ,
356- ) ;
357- }
358- }
359354 }
360-
361- Ok ( config)
362355 }
356+
357+ Ok ( config)
363358 }
364359}
365360
0 commit comments