@@ -290,20 +290,14 @@ pub struct Config {
290290 /// Maximum time in milliseconds for a single push RPC to the worker service. This should be greater than the worker's internal timeout.
291291 pub push_timeout_ms : u64 ,
292292
293- /// The worker service endpoint.
294- pub worker_endpoint : String ,
295-
296293 /// The hostname used to construct `callback_url` for task push requests.
297294 pub callback_addr : String ,
298295
299296 /// The port used to construct `callback_url` for task push requests.
300297 pub callback_port : u32 ,
301298
302- /// Application filter for push mode. When set, only pending activations for this application are considered.
303- pub application : Option < String > ,
304-
305- /// List of namespaces for push mode. When set, application must also be set (store requirement).
306- pub namespaces : Option < Vec < String > > ,
299+ /// Maps every application to its worker endpoint, both represented as strings.
300+ pub worker_map : BTreeMap < String , String > ,
307301}
308302
309303impl Default for Config {
@@ -385,11 +379,9 @@ impl Default for Config {
385379 push_queue_size : 1 ,
386380 push_queue_timeout_ms : 5000 ,
387381 push_timeout_ms : 30000 ,
388- worker_endpoint : "http://127.0.0.1:50052" . into ( ) ,
389382 callback_addr : "0.0.0.0" . into ( ) ,
390383 callback_port : 50051 ,
391- application : None ,
392- namespaces : None ,
384+ worker_map : [ ( "sentry" . into ( ) , "http://127.0.0.1:50052" . into ( ) ) ] . into ( ) ,
393385 }
394386 }
395387}
@@ -527,6 +519,10 @@ mod tests {
527519 assert_eq ! ( config. max_pending_count, 2048 ) ;
528520 assert_eq ! ( config. max_processing_count, 2048 ) ;
529521 assert_eq ! ( config. vacuum_page_count, None ) ;
522+ assert_eq ! (
523+ config. worker_map. get( "sentry" ) . map( String :: as_str) ,
524+ Some ( "http://127.0.0.1:50052" )
525+ ) ;
530526 }
531527
532528 #[ test]
@@ -554,6 +550,9 @@ mod tests {
554550 max_processing_attempts: 5
555551 vacuum_page_count: 1000
556552 full_vacuum_on_start: true
553+ worker_map:
554+ sentry: http://worker-sentry:50052
555+ launchpad: http://worker-launchpad:50053
557556 "# ,
558557 ) ?;
559558 // Env vars always override config file
@@ -588,6 +587,16 @@ mod tests {
588587 assert_eq ! ( config. vacuum_page_count, Some ( 1000 ) ) ;
589588 assert_eq ! ( config. db_max_size, Some ( 3_000_000_000 ) ) ;
590589 assert ! ( config. full_vacuum_on_start) ;
590+ assert_eq ! (
591+ config. worker_map,
592+ BTreeMap :: from( [
593+ ( "sentry" . to_owned( ) , "http://worker-sentry:50052" . to_owned( ) , ) ,
594+ (
595+ "launchpad" . to_owned( ) ,
596+ "http://worker-launchpad:50053" . to_owned( ) ,
597+ ) ,
598+ ] )
599+ ) ;
591600
592601 Ok ( ( ) )
593602 } ) ;
@@ -632,6 +641,35 @@ mod tests {
632641 config. default_metrics_tags,
633642 BTreeMap :: from( [ ( "key" . to_owned( ) , "value" . to_owned( ) ) ] )
634643 ) ;
644+ assert_eq ! (
645+ config. worker_map. get( "sentry" ) . map( String :: as_str) ,
646+ Some ( "http://127.0.0.1:50052" ) ,
647+ "partial env override must not drop worker_map defaults"
648+ ) ;
649+
650+ Ok ( ( ) )
651+ } ) ;
652+ }
653+
654+ /// `worker_map` uses the same env map encoding as `default_metrics_tags` (brace `key=value` pairs).
655+ #[ test]
656+ fn test_worker_map_from_env ( ) {
657+ Jail :: expect_with ( |jail| {
658+ jail. set_env ( "TASKBROKER_LOG_FILTER" , "error" ) ;
659+ jail. set_env (
660+ "TASKBROKER_WORKER_MAP" ,
661+ "{sentry=http://127.0.0.1:60052,launchpad=http://127.0.0.1:60053}" ,
662+ ) ;
663+
664+ let args = Args { config : None } ;
665+ let config = Config :: from_args ( & args) . unwrap ( ) ;
666+ assert_eq ! (
667+ config. worker_map,
668+ BTreeMap :: from( [
669+ ( "sentry" . to_owned( ) , "http://127.0.0.1:60052" . to_owned( ) , ) ,
670+ ( "launchpad" . to_owned( ) , "http://127.0.0.1:60053" . to_owned( ) , ) ,
671+ ] )
672+ ) ;
635673
636674 Ok ( ( ) )
637675 } ) ;
@@ -876,49 +914,4 @@ mod tests {
876914 Ok ( ( ) )
877915 } ) ;
878916 }
879-
880- #[ test]
881- fn test_default_application_and_namespaces ( ) {
882- let config = Config :: default ( ) ;
883- assert_eq ! ( config. application, None ) ;
884- assert_eq ! ( config. namespaces, None ) ;
885- }
886-
887- #[ test]
888- fn test_from_args_application_from_env ( ) {
889- Jail :: expect_with ( |jail| {
890- jail. set_env ( "TASKBROKER_APPLICATION" , "getsentry" ) ;
891-
892- let args = Args { config : None } ;
893- let config = Config :: from_args ( & args) . unwrap ( ) ;
894- assert_eq ! ( config. application. as_deref( ) , Some ( "getsentry" ) ) ;
895- assert_eq ! ( config. namespaces, None ) ;
896-
897- Ok ( ( ) )
898- } ) ;
899- }
900-
901- #[ test]
902- fn test_from_args_application_and_namespaces_from_config_file ( ) {
903- Jail :: expect_with ( |jail| {
904- jail. create_file (
905- "config.yaml" ,
906- r#"
907- application: getsentry
908- namespaces:
909- - ns1
910- - ns2
911- "# ,
912- ) ?;
913-
914- let args = Args {
915- config : Some ( "config.yaml" . to_owned ( ) ) ,
916- } ;
917- let config = Config :: from_args ( & args) . unwrap ( ) ;
918- assert_eq ! ( config. application. as_deref( ) , Some ( "getsentry" ) ) ;
919- assert_eq ! ( config. namespaces, Some ( vec![ "ns1" . into( ) , "ns2" . into( ) ] ) ) ;
920-
921- Ok ( ( ) )
922- } ) ;
923- }
924917}
0 commit comments