@@ -5,8 +5,10 @@ use neon::{
5
5
prelude:: * ,
6
6
types:: { JsBoolean , JsNumber , JsString } ,
7
7
} ;
8
+ use slot_supplier_bridge:: SlotSupplierBridge ;
8
9
use std:: { collections:: HashMap , net:: SocketAddr , sync:: Arc , time:: Duration } ;
9
10
use temporal_client:: HttpConnectProxyOptions ;
11
+ use temporal_sdk_core:: api:: worker:: SlotKind ;
10
12
use temporal_sdk_core:: {
11
13
api:: telemetry:: { Logger , MetricTemporality , TelemetryOptions , TelemetryOptionsBuilder } ,
12
14
api:: {
@@ -25,6 +27,8 @@ use temporal_sdk_core::{
25
27
TlsConfig , TunerHolderOptionsBuilder , Url ,
26
28
} ;
27
29
30
+ mod slot_supplier_bridge;
31
+
28
32
pub enum EphemeralServerConfig {
29
33
TestServer ( TestServerConfig ) ,
30
34
DevServer ( TemporalDevServerConfig ) ,
@@ -65,11 +69,11 @@ pub(crate) trait ObjectHandleConversionsExt {
65
69
& self ,
66
70
cx : & mut FunctionContext ,
67
71
) -> NeonResult < HashMap < String , String > > ;
68
- fn as_slot_supplier (
69
- & self ,
72
+ fn into_slot_supplier < SK : SlotKind + Send + Sync + ' static > (
73
+ self ,
70
74
cx : & mut FunctionContext ,
71
75
rbo : & mut Option < ResourceBasedSlotsOptions > ,
72
- ) -> NeonResult < SlotSupplierOptions > ;
76
+ ) -> NeonResult < SlotSupplierOptions < SK > > ;
73
77
}
74
78
75
79
impl ObjectHandleConversionsExt for Handle < ' _ , JsObject > {
@@ -409,18 +413,18 @@ impl ObjectHandleConversionsExt for Handle<'_, JsObject> {
409
413
if let Some ( wf_slot_supp) =
410
414
js_optional_getter ! ( cx, & tuner, "workflowTaskSlotSupplier" , JsObject )
411
415
{
412
- tuner_holder. workflow_slot_options ( wf_slot_supp. as_slot_supplier ( cx, & mut rbo) ?) ;
416
+ tuner_holder. workflow_slot_options ( wf_slot_supp. into_slot_supplier ( cx, & mut rbo) ?) ;
413
417
}
414
418
if let Some ( act_slot_supp) =
415
419
js_optional_getter ! ( cx, & tuner, "activityTaskSlotSupplier" , JsObject )
416
420
{
417
- tuner_holder. activity_slot_options ( act_slot_supp. as_slot_supplier ( cx, & mut rbo) ?) ;
421
+ tuner_holder. activity_slot_options ( act_slot_supp. into_slot_supplier ( cx, & mut rbo) ?) ;
418
422
}
419
423
if let Some ( local_act_slot_supp) =
420
424
js_optional_getter ! ( cx, & tuner, "localActivityTaskSlotSupplier" , JsObject )
421
425
{
422
426
tuner_holder. local_activity_slot_options (
423
- local_act_slot_supp. as_slot_supplier ( cx, & mut rbo) ?,
427
+ local_act_slot_supp. into_slot_supplier ( cx, & mut rbo) ?,
424
428
) ;
425
429
}
426
430
if let Some ( rbo) = rbo {
@@ -567,20 +571,20 @@ impl ObjectHandleConversionsExt for Handle<'_, JsObject> {
567
571
}
568
572
}
569
573
570
- fn as_slot_supplier (
571
- & self ,
574
+ fn into_slot_supplier < SK : SlotKind + Send + Sync + ' static > (
575
+ self ,
572
576
cx : & mut FunctionContext ,
573
577
rbo : & mut Option < ResourceBasedSlotsOptions > ,
574
- ) -> NeonResult < SlotSupplierOptions > {
575
- match js_value_getter ! ( cx, self , "type" , JsString ) . as_str ( ) {
578
+ ) -> NeonResult < SlotSupplierOptions < SK > > {
579
+ match js_value_getter ! ( cx, & self , "type" , JsString ) . as_str ( ) {
576
580
"fixed-size" => Ok ( SlotSupplierOptions :: FixedSize {
577
- slots : js_value_getter ! ( cx, self , "numSlots" , JsNumber ) as usize ,
581
+ slots : js_value_getter ! ( cx, & self , "numSlots" , JsNumber ) as usize ,
578
582
} ) ,
579
583
"resource-based" => {
580
- let min_slots = js_value_getter ! ( cx, self , "minimumSlots" , JsNumber ) ;
581
- let max_slots = js_value_getter ! ( cx, self , "maximumSlots" , JsNumber ) ;
582
- let ramp_throttle = js_value_getter ! ( cx, self , "rampThrottleMs" , JsNumber ) as u64 ;
583
- if let Some ( tuner_opts) = js_optional_getter ! ( cx, self , "tunerOptions" , JsObject ) {
584
+ let min_slots = js_value_getter ! ( cx, & self , "minimumSlots" , JsNumber ) ;
585
+ let max_slots = js_value_getter ! ( cx, & self , "maximumSlots" , JsNumber ) ;
586
+ let ramp_throttle = js_value_getter ! ( cx, & self , "rampThrottleMs" , JsNumber ) as u64 ;
587
+ if let Some ( tuner_opts) = js_optional_getter ! ( cx, & self , "tunerOptions" , JsObject ) {
584
588
let target_mem =
585
589
js_value_getter ! ( cx, & tuner_opts, "targetMemoryUsage" , JsNumber ) ;
586
590
let target_cpu = js_value_getter ! ( cx, & tuner_opts, "targetCpuUsage" , JsNumber ) ;
@@ -603,6 +607,10 @@ impl ObjectHandleConversionsExt for Handle<'_, JsObject> {
603
607
) ,
604
608
) )
605
609
}
610
+ "custom" => {
611
+ let ssb = SlotSupplierBridge :: new ( cx, self ) ?;
612
+ Ok ( SlotSupplierOptions :: Custom ( Arc :: new ( ssb) ) )
613
+ }
606
614
_ => cx. throw_type_error ( "Invalid slot supplier type" ) ,
607
615
}
608
616
}
0 commit comments