11use crate :: {
2+ client:: DracoRuntimeStatusService ,
23 config:: AdapterConfig ,
34 store:: AdapterStore ,
45 traits:: { LoadConfig , Server as AdapterServer } ,
@@ -8,6 +9,7 @@ use std::sync::Arc;
89use tokio:: signal;
910use tonic:: transport:: Server ;
1011use tonic_health:: pb:: health_server:: HealthServer ;
12+ use tucana:: shared:: { AdapterConfiguration , RuntimeFeature } ;
1113
1214/// Context passed to adapter server implementations containing all shared resources
1315pub struct ServerContext < C : LoadConfig > {
@@ -23,6 +25,11 @@ pub struct ServerRunner<C: LoadConfig> {
2325}
2426
2527impl < C : LoadConfig > ServerRunner < C > {
28+
29+ pub fn get_server_config ( & self ) -> Arc < C > {
30+ self . context . server_config . clone ( )
31+ }
32+
2633 pub async fn new < S : AdapterServer < C > > ( server : S ) -> anyhow:: Result < Self > {
2734 env_logger:: Builder :: from_default_env ( )
2835 . filter_level ( log:: LevelFilter :: Debug )
@@ -50,11 +57,34 @@ impl<C: LoadConfig> ServerRunner<C> {
5057 } )
5158 }
5259
53- pub async fn serve ( self ) -> anyhow:: Result < ( ) > {
60+ pub async fn serve (
61+ self ,
62+ runtime_feature : Vec < RuntimeFeature > ,
63+ runtime_config : Vec < AdapterConfiguration > ,
64+ ) -> anyhow:: Result < ( ) > {
5465 let config = self . context . adapter_config . clone ( ) ;
66+ let mut runtime_status_service: Option < DracoRuntimeStatusService > = None ;
67+
5568 log:: info!( "Starting Draco Variant: {}" , config. draco_variant) ;
5669
5770 if !config. is_static ( ) {
71+ runtime_status_service = Some (
72+ DracoRuntimeStatusService :: from_url (
73+ config. aquila_url . clone ( ) ,
74+ config. draco_variant . clone ( ) ,
75+ runtime_feature,
76+ runtime_config,
77+ )
78+ . await ,
79+ ) ;
80+
81+ if let Some ( ser) = & runtime_status_service {
82+ ser. update_runtime_status_by_status (
83+ tucana:: shared:: adapter_runtime_status:: Status :: NotReady ,
84+ )
85+ . await ;
86+ } ;
87+
5888 let definition_service = FlowUpdateService :: from_url (
5989 config. aquila_url . clone ( ) ,
6090 config. definition_path . as_str ( ) ,
@@ -95,6 +125,13 @@ impl<C: LoadConfig> ServerRunner<C> {
95125 } = self ;
96126 // Init the adapter server (e.g. create underlying HTTP server)
97127 server. init ( & context) . await ?;
128+
129+ if let Some ( ser) = & runtime_status_service {
130+ ser. update_runtime_status_by_status (
131+ tucana:: shared:: adapter_runtime_status:: Status :: Running ,
132+ )
133+ . await ;
134+ } ;
98135 log:: info!( "Draco successfully initialized." ) ;
99136
100137 #[ cfg( unix) ]
@@ -158,6 +195,12 @@ impl<C: LoadConfig> ServerRunner<C> {
158195 }
159196 }
160197 }
198+ if let Some ( ser) = & runtime_status_service {
199+ ser. update_runtime_status_by_status (
200+ tucana:: shared:: adapter_runtime_status:: Status :: Stopped ,
201+ )
202+ . await ;
203+ } ;
161204
162205 log:: info!( "Draco shutdown complete" ) ;
163206 Ok ( ( ) )
0 commit comments