@@ -10,7 +10,9 @@ use code0_flow::flow_config::load_env_file;
1010use context:: { Context , ContextEntry , ContextResult } ;
1111use error:: RuntimeError ;
1212use futures_lite:: StreamExt ;
13+ use log:: error;
1314use prost:: Message ;
15+ use tonic_health:: pb:: health_server:: HealthServer ;
1416use registry:: FunctionStore ;
1517use tucana:: shared:: value:: Kind ;
1618use tucana:: shared:: { ExecutionFlow , ListValue , NodeFunction , Value } ;
@@ -170,13 +172,34 @@ async fn main() {
170172 let mut store = FunctionStore :: new ( ) ;
171173 store. populate ( collect ( ) ) ;
172174
173- let client = match async_nats:: connect ( "nats://127.0.0.1:4222" ) . await {
175+ let client = match async_nats:: connect ( config . nats_url . clone ( ) ) . await {
174176 Ok ( client) => client,
175177 Err ( err) => {
176178 panic ! ( "Failed to connect to NATS server: {}" , err) ;
177179 }
178180 } ;
179181
182+ if config. with_health_service {
183+ let health_service =
184+ code0_flow:: flow_health:: HealthService :: new ( config. nats_url . clone ( ) ) ;
185+ let address = match format ! ( "{}:{}" , config. grpc_host, config. grpc_port) . parse ( ) {
186+ Ok ( address) => address,
187+ Err ( err) => {
188+ error ! ( "Failed to parse grpc address: {:?}" , err) ;
189+ return ;
190+ }
191+ } ;
192+
193+ tokio:: spawn ( async move {
194+ let _ = tonic:: transport:: Server :: builder ( )
195+ . add_service ( HealthServer :: new ( health_service) )
196+ . serve ( address)
197+ . await ;
198+ } ) ;
199+
200+ println ! ( "Health server started at {}" , address) ;
201+ }
202+
180203 let _ = match client
181204 . queue_subscribe ( String :: from ( "execution.*" ) , "taurus" . into ( ) )
182205 . await
@@ -193,12 +216,9 @@ async fn main() {
193216 }
194217 } ;
195218
196- let value = match handle_message ( flow, & store) {
197- Some ( value) => value,
198- None => Value {
199- kind : Some ( Kind :: NullValue ( 0 ) ) ,
200- } ,
201- } ;
219+ let value = handle_message ( flow, & store) . unwrap_or_else ( || Value {
220+ kind : Some ( Kind :: NullValue ( 0 ) ) ,
221+ } ) ;
202222
203223 // Send a response to the reply subject
204224 if let Some ( reply) = msg. reply {
0 commit comments