@@ -12,6 +12,7 @@ use event_worker::events::{
12
12
use hyper:: { Body , Request , Response } ;
13
13
use log:: { debug, error} ;
14
14
use sb_core:: conn_sync:: ConnSync ;
15
+ use sb_core:: WorkerMetricSource ;
15
16
use sb_graph:: EszipPayloadKind ;
16
17
use sb_workers:: context:: {
17
18
EventWorkerRuntimeOpts , MainWorkerRuntimeOpts , Timing , UserWorkerMsgs , WorkerContextInitOpts ,
@@ -309,9 +310,10 @@ impl CreateWorkerArgs {
309
310
310
311
pub async fn create_worker < Opt : Into < CreateWorkerArgs > > (
311
312
init_opts : Opt ,
312
- ) -> Result < mpsc:: UnboundedSender < WorkerRequestMsg > , Error > {
313
- let ( worker_boot_result_tx, worker_boot_result_rx) = oneshot:: channel :: < Result < ( ) , Error > > ( ) ;
313
+ ) -> Result < ( WorkerMetricSource , mpsc:: UnboundedSender < WorkerRequestMsg > ) , Error > {
314
314
let ( unix_stream_tx, unix_stream_rx) = mpsc:: unbounded_channel :: < UnixStreamEntry > ( ) ;
315
+ let ( worker_boot_result_tx, worker_boot_result_rx) =
316
+ oneshot:: channel :: < Result < WorkerMetricSource , Error > > ( ) ;
315
317
316
318
let CreateWorkerArgs ( init_opts, maybe_supervisor_policy, maybe_termination_token) =
317
319
init_opts. into ( ) ;
@@ -370,7 +372,7 @@ pub async fn create_worker<Opt: Into<CreateWorkerArgs>>(
370
372
371
373
bail ! ( err)
372
374
}
373
- Ok ( _ ) => {
375
+ Ok ( metric ) => {
374
376
let elapsed = worker_struct_ref
375
377
. worker_boot_start_time
376
378
. elapsed ( )
@@ -384,7 +386,7 @@ pub async fn create_worker<Opt: Into<CreateWorkerArgs>>(
384
386
worker_struct_ref. event_metadata . clone ( ) ,
385
387
) ;
386
388
387
- Ok ( worker_req_tx)
389
+ Ok ( ( metric , worker_req_tx) )
388
390
}
389
391
}
390
392
} else {
@@ -422,7 +424,7 @@ pub async fn create_main_worker(
422
424
main_worker_path : PathBuf ,
423
425
import_map_path : Option < String > ,
424
426
no_module_cache : bool ,
425
- user_worker_msgs_tx : mpsc :: UnboundedSender < UserWorkerMsgs > ,
427
+ runtime_opts : MainWorkerRuntimeOpts ,
426
428
maybe_entrypoint : Option < String > ,
427
429
termination_token : Option < TerminationToken > ,
428
430
) -> Result < mpsc:: UnboundedSender < WorkerRequestMsg > , Error > {
@@ -435,7 +437,7 @@ pub async fn create_main_worker(
435
437
}
436
438
}
437
439
438
- let main_worker_req_tx = create_worker ( (
440
+ let ( _ , sender ) = create_worker ( (
439
441
WorkerContextInitOpts {
440
442
service_path,
441
443
import_map_path,
@@ -445,17 +447,15 @@ pub async fn create_main_worker(
445
447
maybe_eszip,
446
448
maybe_entrypoint,
447
449
maybe_module_code : None ,
448
- conf : WorkerRuntimeOpts :: MainWorker ( MainWorkerRuntimeOpts {
449
- worker_pool_tx : user_worker_msgs_tx,
450
- } ) ,
450
+ conf : WorkerRuntimeOpts :: MainWorker ( runtime_opts) ,
451
451
env_vars : std:: env:: vars ( ) . collect ( ) ,
452
452
} ,
453
453
termination_token,
454
454
) )
455
455
. await
456
456
. map_err ( |err| anyhow ! ( "main worker boot error: {}" , err) ) ?;
457
457
458
- Ok ( main_worker_req_tx )
458
+ Ok ( sender )
459
459
}
460
460
461
461
pub async fn create_events_worker (
@@ -464,7 +464,13 @@ pub async fn create_events_worker(
464
464
no_module_cache : bool ,
465
465
maybe_entrypoint : Option < String > ,
466
466
termination_token : Option < TerminationToken > ,
467
- ) -> Result < mpsc:: UnboundedSender < WorkerEventWithMetadata > , Error > {
467
+ ) -> Result <
468
+ (
469
+ WorkerMetricSource ,
470
+ mpsc:: UnboundedSender < WorkerEventWithMetadata > ,
471
+ ) ,
472
+ Error ,
473
+ > {
468
474
let ( events_tx, events_rx) = mpsc:: unbounded_channel :: < WorkerEventWithMetadata > ( ) ;
469
475
470
476
let mut service_path = events_worker_path. clone ( ) ;
@@ -478,7 +484,7 @@ pub async fn create_events_worker(
478
484
}
479
485
}
480
486
481
- let _ = create_worker ( (
487
+ let ( metric , _ ) = create_worker ( (
482
488
WorkerContextInitOpts {
483
489
service_path,
484
490
no_module_cache,
@@ -496,7 +502,7 @@ pub async fn create_events_worker(
496
502
. await
497
503
. map_err ( |err| anyhow ! ( "events worker boot error: {}" , err) ) ?;
498
504
499
- Ok ( events_tx)
505
+ Ok ( ( metric , events_tx) )
500
506
}
501
507
502
508
pub async fn create_user_worker_pool (
0 commit comments