@@ -6,23 +6,23 @@ use std::{
66} ;
77
88use crate :: {
9+ ROOT_MOD ,
910 client:: Client ,
1011 enter_sync, error, id, new_error,
1112 runtime:: { AsyncCommand , Runtime , RuntimeHandle } ,
1213 util:: { AsyncCallback , Struct } ,
13- ROOT_MOD ,
1414} ;
15+ use futures:: { StreamExt , stream:: BoxStream } ;
1516use futures:: { future, stream} ;
16- use futures:: { stream:: BoxStream , StreamExt } ;
1717use magnus:: {
18- class , function , method , prelude :: * , typed_data , DataTypeFunctions , Error , IntoValue , RArray ,
19- RString , RTypedData , Ruby , TypedData , Value ,
18+ DataTypeFunctions , Error , IntoValue , RArray , RString , RTypedData , Ruby , TypedData , Value ,
19+ class , function , method , prelude :: * , typed_data ,
2020} ;
2121use prost:: Message ;
2222use temporal_sdk_core:: {
23- replay:: { HistoryForReplay , ReplayWorkerInput } ,
2423 ResourceBasedSlotsOptions , ResourceBasedSlotsOptionsBuilder , ResourceSlotOptions ,
2524 SlotSupplierOptions , TunerHolder , TunerHolderOptionsBuilder , WorkerConfig , WorkerConfigBuilder ,
25+ replay:: { HistoryForReplay , ReplayWorkerInput } ,
2626} ;
2727use temporal_sdk_core_api:: {
2828 errors:: { PollError , WorkflowErrorType } ,
@@ -34,7 +34,7 @@ use temporal_sdk_core_api::{
3434use temporal_sdk_core_protos:: coresdk:: workflow_completion:: WorkflowActivationCompletion ;
3535use temporal_sdk_core_protos:: coresdk:: { ActivityHeartbeat , ActivityTaskCompletion } ;
3636use temporal_sdk_core_protos:: temporal:: api:: history:: v1:: History ;
37- use tokio:: sync:: mpsc:: { channel , Sender } ;
37+ use tokio:: sync:: mpsc:: { Sender , channel } ;
3838use tokio_stream:: wrappers:: ReceiverStream ;
3939
4040pub fn init ( ruby : & Ruby ) -> Result < ( ) , Error > {
@@ -480,15 +480,21 @@ fn build_config(options: Struct) -> Result<WorkerConfig, Error> {
480480 } )
481481 . client_identity_override ( options. member :: < Option < String > > ( id ! ( "identity_override" ) ) ?)
482482 . max_cached_workflows ( options. member :: < usize > ( id ! ( "max_cached_workflows" ) ) ?)
483- . workflow_task_poller_behavior ( PollerBehavior :: SimpleMaximum (
484- options. member :: < usize > ( id ! ( "max_concurrent_workflow_task_polls" ) ) ?,
485- ) )
483+ . workflow_task_poller_behavior ( {
484+ let poller_behavior = options
485+ . child ( id ! ( "workflow_task_poller_behavior" ) ) ?
486+ . ok_or_else ( || error ! ( "Worker options must have workflow_task_poller_behavior" ) ) ?;
487+ extract_poller_behavior ( poller_behavior) ?
488+ } )
486489 . nonsticky_to_sticky_poll_ratio (
487490 options. member :: < f32 > ( id ! ( "nonsticky_to_sticky_poll_ratio" ) ) ?,
488491 )
489- . activity_task_poller_behavior ( PollerBehavior :: SimpleMaximum (
490- options. member :: < usize > ( id ! ( "max_concurrent_activity_task_polls" ) ) ?,
491- ) )
492+ . activity_task_poller_behavior ( {
493+ let poller_behavior = options
494+ . child ( id ! ( "activity_task_poller_behavior" ) ) ?
495+ . ok_or_else ( || error ! ( "Worker options must have activity_task_poller_behavior" ) ) ?;
496+ extract_poller_behavior ( poller_behavior) ?
497+ } )
492498 . no_remote_activities ( options. member :: < bool > ( id ! ( "no_remote_activities" ) ) ?)
493499 . sticky_queue_schedule_to_start_timeout ( Duration :: from_secs_f64 (
494500 options. member ( id ! ( "sticky_queue_schedule_to_start_timeout" ) ) ?,
@@ -605,3 +611,15 @@ fn build_tuner_resource_options<SK: SlotKind>(
605611 Some ( slots_options) ,
606612 ) )
607613}
614+
615+ fn extract_poller_behavior ( poller_behavior : Struct ) -> Result < PollerBehavior , Error > {
616+ Ok ( if poller_behavior. member :: < usize > ( id ! ( "initial" ) ) . is_ok ( ) {
617+ PollerBehavior :: Autoscaling {
618+ minimum : poller_behavior. member :: < usize > ( id ! ( "minimum" ) ) ?,
619+ maximum : poller_behavior. member :: < usize > ( id ! ( "maximum" ) ) ?,
620+ initial : poller_behavior. member :: < usize > ( id ! ( "initial" ) ) ?,
621+ }
622+ } else {
623+ PollerBehavior :: SimpleMaximum ( poller_behavior. member :: < usize > ( id ! ( "maximum" ) ) ?)
624+ } )
625+ }
0 commit comments