@@ -240,6 +240,40 @@ pub struct WorkerConfig {
240240 pub skip_client_worker_set_check : bool ,
241241}
242242
243+ impl WorkerConfig {
244+ /// Returns true if the configuration specifies we should fail a workflow on a certain error
245+ /// type rather than failing the workflow task.
246+ pub fn should_fail_workflow (
247+ & self ,
248+ workflow_type : & str ,
249+ error_type : & WorkflowErrorType ,
250+ ) -> bool {
251+ self . workflow_failure_errors . contains ( error_type)
252+ || self
253+ . workflow_types_to_failure_errors
254+ . get ( workflow_type)
255+ . map ( |s| s. contains ( error_type) )
256+ . unwrap_or ( false )
257+ }
258+
259+ pub fn computed_deployment_version ( & self ) -> Option < WorkerDeploymentVersion > {
260+ let wdv = match self . versioning_strategy {
261+ WorkerVersioningStrategy :: None { ref build_id } => WorkerDeploymentVersion {
262+ deployment_name : "" . to_owned ( ) ,
263+ build_id : build_id. clone ( ) ,
264+ } ,
265+ WorkerVersioningStrategy :: WorkerDeploymentBased ( ref opts) => opts. version . clone ( ) ,
266+ WorkerVersioningStrategy :: LegacyBuildIdBased { ref build_id } => {
267+ WorkerDeploymentVersion {
268+ deployment_name : "" . to_owned ( ) ,
269+ build_id : build_id. clone ( ) ,
270+ }
271+ }
272+ } ;
273+ if wdv. is_empty ( ) { None } else { Some ( wdv) }
274+ }
275+ }
276+
243277impl < S : worker_config_builder:: IsComplete > WorkerConfigBuilder < S > {
244278 pub fn build ( self ) -> Result < WorkerConfig , String > {
245279 let config = self . build_internal ( ) ;
@@ -260,12 +294,12 @@ impl<S: worker_config_builder::IsComplete> WorkerConfigBuilder<S> {
260294 config. nexus_task_poller_behavior . validate ( ) ?;
261295
262296 if let Some ( ref x) = config. max_worker_activities_per_second
263- && ( !x. is_normal ( ) || x. is_sign_negative ( ) ) {
264- return Err (
265- "`max_worker_activities_per_second` must be positive and nonzero"
266- . to_string ( ) ,
267- ) ;
268- }
297+ && ( !x. is_normal ( ) || x. is_sign_negative ( ) )
298+ {
299+ return Err (
300+ "`max_worker_activities_per_second` must be positive and nonzero" . to_string ( ) ,
301+ ) ;
302+ }
269303
270304 if matches ! ( config. max_outstanding_workflow_tasks, Some ( v) if v == 0 ) {
271305 return Err ( "`max_outstanding_workflow_tasks` must be > 0" . to_string ( ) ) ;
@@ -282,9 +316,13 @@ impl<S: worker_config_builder::IsComplete> WorkerConfigBuilder<S> {
282316
283317 if config. max_cached_workflows > 0 {
284318 if let Some ( max_wft) = config. max_outstanding_workflow_tasks
285- && max_wft < 2 {
286- return Err ( "`max_cached_workflows` > 0 requires `max_outstanding_workflow_tasks` >= 2" . to_string ( ) ) ;
287- }
319+ && max_wft < 2
320+ {
321+ return Err (
322+ "`max_cached_workflows` > 0 requires `max_outstanding_workflow_tasks` >= 2"
323+ . to_string ( ) ,
324+ ) ;
325+ }
288326 if matches ! ( config. workflow_task_poller_behavior, PollerBehavior :: SimpleMaximum ( u) if u < 2 )
289327 {
290328 return Err ( "`max_cached_workflows` > 0 requires `workflow_task_poller_behavior` to be at least 2" . to_string ( ) ) ;
@@ -325,44 +363,6 @@ impl<S: worker_config_builder::IsComplete> WorkerConfigBuilder<S> {
325363 }
326364}
327365
328- impl WorkerConfig {
329- /// Returns true if the configuration specifies we should fail a workflow on a certain error
330- /// type rather than failing the workflow task.
331- pub fn should_fail_workflow (
332- & self ,
333- workflow_type : & str ,
334- error_type : & WorkflowErrorType ,
335- ) -> bool {
336- self . workflow_failure_errors . contains ( error_type)
337- || self
338- . workflow_types_to_failure_errors
339- . get ( workflow_type)
340- . map ( |s| s. contains ( error_type) )
341- . unwrap_or ( false )
342- }
343-
344- pub fn computed_deployment_version ( & self ) -> Option < WorkerDeploymentVersion > {
345- let wdv = match self . versioning_strategy {
346- WorkerVersioningStrategy :: None { ref build_id } => WorkerDeploymentVersion {
347- deployment_name : "" . to_owned ( ) ,
348- build_id : build_id. clone ( ) ,
349- } ,
350- WorkerVersioningStrategy :: WorkerDeploymentBased ( ref opts) => opts. version . clone ( ) ,
351- WorkerVersioningStrategy :: LegacyBuildIdBased { ref build_id } => {
352- WorkerDeploymentVersion {
353- deployment_name : "" . to_owned ( ) ,
354- build_id : build_id. clone ( ) ,
355- }
356- }
357- } ;
358- if wdv. is_empty ( ) { None } else { Some ( wdv) }
359- }
360- }
361-
362- // Note: WorkerConfigBuilder is now generated by bon.
363- // The custom clear_max_outstanding_opts method is removed because bon's builder
364- // doesn't support custom methods the same way. Users should manually unset these fields if needed.
365-
366366/// This trait allows users to customize the performance characteristics of workers dynamically.
367367/// For more, see the docstrings of the traits in the return types of its functions.
368368pub trait WorkerTuner {
0 commit comments