44 In some conditions Sagittarius can't connect to Aquila
55 Thus Aquila sends a `Logon` request to connect to Sagittarius establishing the connection
66*/
7- use futures:: StreamExt ;
7+ use futures:: { StreamExt , TryStreamExt } ;
88use prost:: Message ;
99use std:: {
1010 collections:: HashMap ,
@@ -20,7 +20,7 @@ use tucana::sagittarius::execution_service_client::ExecutionServiceClient;
2020use tucana:: sagittarius:: { ExecutionLogonRequest , Logon } ;
2121use tucana:: shared:: { ExecutionFlow , ExecutionResult , ValidationFlow } ;
2222
23- use crate :: authorization:: authorization:: get_authorization_metadata;
23+ use crate :: { authorization:: authorization:: get_authorization_metadata, flow :: key_has_flow_id } ;
2424
2525const EXECUTION_FLOW_ID_TTL : Duration = Duration :: from_secs ( 30 * 60 ) ;
2626const MAX_EXECUTION_FLOW_IDS : usize = 10_000 ;
@@ -276,7 +276,44 @@ impl SagittariusTestExecutionServiceClient {
276276 }
277277
278278 async fn load_validation_flow ( & self , flow_id : i64 ) -> Option < ValidationFlow > {
279- match self . store . get ( format ! ( "*.*.*.{}" , flow_id) ) . await {
279+ let mut keys = match self . store . keys ( ) . await {
280+ Ok ( keys) => keys,
281+ Err ( err) => {
282+ log:: error!(
283+ "Failed to list validation flow keys flow_id={} error={:?}" ,
284+ flow_id,
285+ err
286+ ) ;
287+ return None ;
288+ }
289+ } ;
290+
291+ let key = loop {
292+ match keys. try_next ( ) . await {
293+ Ok ( Some ( key) ) if key_has_flow_id ( & key, flow_id) => break key,
294+ Ok ( Some ( _) ) => { }
295+ Ok ( None ) => {
296+ log:: error!( "Validation flow was not found flow_id={}" , flow_id) ;
297+ return None ;
298+ }
299+ Err ( err) => {
300+ log:: error!(
301+ "Failed while scanning validation flow keys flow_id={} error={:?}" ,
302+ flow_id,
303+ err
304+ ) ;
305+ return None ;
306+ }
307+ }
308+ } ;
309+
310+ log:: debug!(
311+ "Resolved validation flow key flow_id={} key={}" ,
312+ flow_id,
313+ key
314+ ) ;
315+
316+ match self . store . get ( & key) . await {
280317 Ok ( Some ( bytes) ) => match ValidationFlow :: decode ( bytes) {
281318 Ok ( flow) => {
282319 log:: debug!(
@@ -298,13 +335,18 @@ impl SagittariusTestExecutionServiceClient {
298335 }
299336 } ,
300337 Ok ( None ) => {
301- log:: error!( "Validation flow was not found flow_id={}" , flow_id) ;
338+ log:: error!(
339+ "Validation flow disappeared after key resolution flow_id={} key={}" ,
340+ flow_id,
341+ key
342+ ) ;
302343 None
303344 }
304345 Err ( err) => {
305346 log:: error!(
306- "Failed to fetch validation flow flow_id={} error={:?}" ,
347+ "Failed to fetch validation flow flow_id={} key={} error={:?}" ,
307348 flow_id,
349+ key,
308350 err
309351 ) ;
310352 None
0 commit comments