@@ -36,6 +36,10 @@ macro_rules! enter_sync {
3636pub  fn  init ( cx :  & mut  neon:: prelude:: ModuleContext )  -> neon:: prelude:: NeonResult < ( ) >  { 
3737    cx. export_function ( "newRuntime" ,  runtime_new) ?; 
3838    cx. export_function ( "runtimeShutdown" ,  runtime_shutdown) ?; 
39+     // cx.export_function( 
40+     //     "runtimeGetWorkerHeartbeatIntervalMillis", 
41+     //     runtime_get_worker_heartbeat_interval_millis, 
42+     // )?; 
3943
4044    Ok ( ( ) ) 
4145} 
@@ -51,6 +55,7 @@ pub struct Runtime {
5155    // For some unknown reason, the otel metrics exporter will go crazy on shutdown in some 
5256    // scenarios if we don't hold on to the `CoreOtelMeter` till the `Runtime` finally gets dropped. 
5357    _otel_metrics_exporter :  Option < Arc < dyn  CoreMeter  + ' static > > , 
58+     // worker_heartbeat_interval_millis: Option<u64>, 
5459} 
5560
5661/// Initialize Core global telemetry and create the tokio runtime required to run Core. 
@@ -59,11 +64,13 @@ pub struct Runtime {
5964pub  fn  runtime_new ( 
6065    bridge_options :  config:: RuntimeOptions , 
6166)  -> BridgeResult < OpaqueOutboundHandle < Runtime > >  { 
62-     let  ( telemetry_options,  metrics_options,  logging_options)  = bridge_options. try_into ( ) ?; 
67+     let  ( telemetry_options,  metrics_options,  logging_options,  worker_heartbeat_interval_millis)  =
68+         bridge_options. try_into ( ) ?; 
6369
6470    // Create core runtime which starts tokio multi-thread runtime 
6571    let  runtime_options = RuntimeOptionsBuilder :: default ( ) 
6672        . telemetry_options ( telemetry_options) 
73+         . heartbeat_interval ( worker_heartbeat_interval_millis. map ( Duration :: from_millis) ) 
6774        . build ( ) 
6875        . context ( "Failed to build runtime options" ) ?; 
6976    let  mut  core_runtime = CoreRuntime :: new ( runtime_options,  TokioRuntimeBuilder :: default ( ) ) 
@@ -125,6 +132,7 @@ pub fn runtime_new(
125132        log_exporter_task, 
126133        metrics_exporter_task :  prom_metrics_exporter_task. map ( Arc :: new) , 
127134        _otel_metrics_exporter :  otel_metrics_exporter, 
135+         // worker_heartbeat_interval_millis: runtime_options.worker_heartbeat_interval.map(|d| d.as_millis() as u64), 
128136    } ) ) 
129137} 
130138
@@ -138,6 +146,21 @@ pub fn runtime_shutdown(runtime: OpaqueInboundHandle<Runtime>) -> BridgeResult<(
138146    Ok ( ( ) ) 
139147} 
140148
149+ // #[js_function] 
150+ // pub fn runtime_get_worker_heartbeat_interval_millis( 
151+ //     runtime: OpaqueInboundHandle<Runtime>, 
152+ // ) -> BridgeResult<Option<u32>> { 
153+ //     runtime 
154+ //         .borrow()? 
155+ //         .worker_heartbeat_interval_millis 
156+ //         .map(u32::try_from) 
157+ //         .transpose() 
158+ //         .map_err(|_| BridgeError::TypeError { 
159+ //             field: None, 
160+ //             message: "workerHeartbeatIntervalMillis is too large to represent in JavaScript".into(), 
161+ //         }) 
162+ // } 
163+ 
141164/// Drop will handle the cleanup 
142165impl  MutableFinalize  for  Runtime  { } 
143166
@@ -265,6 +288,7 @@ mod config {
265288        log_exporter :  LogExporterOptions , 
266289        telemetry :  TelemetryOptions , 
267290        metrics_exporter :  Option < MetricsExporterOptions > , 
291+         worker_heartbeat_interval_millis :  Option < u64 > , 
268292    } 
269293
270294    #[ derive( Debug ,  Clone ,  TryFromJs ) ]  
@@ -321,6 +345,7 @@ mod config {
321345            CoreTelemetryOptions , 
322346            Option < super :: BridgeMetricsExporter > , 
323347            super :: BridgeLogExporter , 
348+             Option < u64 > , 
324349        ) >  for  RuntimeOptions 
325350    { 
326351        type  Error  = BridgeError ; 
@@ -330,8 +355,16 @@ mod config {
330355            CoreTelemetryOptions , 
331356            Option < super :: BridgeMetricsExporter > , 
332357            super :: BridgeLogExporter , 
358+             Option < u64 > , 
333359        ) >  { 
334-             let  ( telemetry_logger,  log_exporter)  = match  self . log_exporter  { 
360+             let  Self  { 
361+                 log_exporter, 
362+                 telemetry, 
363+                 metrics_exporter, 
364+                 worker_heartbeat_interval_millis, 
365+             }  = self ; 
366+ 
367+             let  ( telemetry_logger,  log_exporter)  = match  log_exporter { 
335368                LogExporterOptions :: Console  {  filter }  => ( 
336369                    CoreTelemetryLogger :: Console  {  filter } , 
337370                    BridgeLogExporter :: Console , 
@@ -351,17 +384,21 @@ mod config {
351384            let  mut  telemetry_options = TelemetryOptionsBuilder :: default ( ) ; 
352385            let  telemetry_options = telemetry_options
353386                . logging ( telemetry_logger) 
354-                 . metric_prefix ( self . telemetry . metric_prefix ) 
355-                 . attach_service_name ( self . telemetry . attach_service_name ) 
387+                 . metric_prefix ( telemetry. metric_prefix ) 
388+                 . attach_service_name ( telemetry. attach_service_name ) 
356389                . build ( ) 
357390                . context ( "Failed to build telemetry options" ) ?; 
358391
359-             let  metrics_exporter = self 
360-                 . metrics_exporter 
392+             let  metrics_exporter = metrics_exporter
361393                . map ( std:: convert:: TryInto :: try_into) 
362394                . transpose ( ) ?; 
363395
364-             Ok ( ( telemetry_options,  metrics_exporter,  log_exporter) ) 
396+             Ok ( ( 
397+                 telemetry_options, 
398+                 metrics_exporter, 
399+                 log_exporter, 
400+                 worker_heartbeat_interval_millis, 
401+             ) ) 
365402        } 
366403    } 
367404
0 commit comments