@@ -14,6 +14,23 @@ use tucana::{
1414
1515use std:: sync:: atomic:: { AtomicBool , Ordering } ;
1616
17+ fn module_config_stats ( configs : & tucana:: shared:: ModuleConfigurations ) -> ( usize , usize ) {
18+ let project_count = configs. module_configurations . len ( ) ;
19+ let config_count = configs
20+ . module_configurations
21+ . iter ( )
22+ . map ( |project_cfg| project_cfg. module_configurations . len ( ) )
23+ . sum ( ) ;
24+
25+ ( project_count, config_count)
26+ }
27+
28+ fn key_has_flow_id ( key : & str , flow_id : i64 ) -> bool {
29+ key. rsplit_once ( '.' )
30+ . and_then ( |( _, id) | id. parse :: < i64 > ( ) . ok ( ) )
31+ == Some ( flow_id)
32+ }
33+
1734#[ derive( Clone ) ]
1835pub struct SagittariusFlowClient {
1936 store : Arc < async_nats:: jetstream:: kv:: Store > ,
@@ -103,11 +120,44 @@ impl SagittariusFlowClient {
103120 match data {
104121 Data :: DeletedFlowId ( id) => {
105122 log:: info!( "Deleting the Flow with the id: {}" , id) ;
106- let identifier = format ! ( "{}::*" , id) ;
107- match self . store . delete ( identifier) . await {
108- Ok ( _) => log:: info!( "Flow deleted successfully" ) ,
109- Err ( err) => log:: error!( "Failed to delete flow. Reason: {:?}" , err) ,
123+ let mut keys = match self . store . keys ( ) . await {
124+ Ok ( keys) => keys. boxed ( ) ,
125+ Err ( err) => {
126+ log:: error!(
127+ "Failed to list flows while deleting flow {}. Reason: {:?}" ,
128+ id,
129+ err
130+ ) ;
131+ return ;
132+ }
110133 } ;
134+
135+ let mut deleted_count = 0 ;
136+ while let Ok ( Some ( key) ) = keys. try_next ( ) . await {
137+ if !key_has_flow_id ( & key, id) {
138+ continue ;
139+ }
140+
141+ match self . store . delete ( & key) . await {
142+ Ok ( _) => deleted_count += 1 ,
143+ Err ( err) => log:: error!(
144+ "Failed to delete flow {} with key {}. Reason: {:?}" ,
145+ id,
146+ key,
147+ err
148+ ) ,
149+ }
150+ }
151+
152+ if deleted_count == 0 {
153+ log:: warn!( "No stored flow found with the id: {}" , id) ;
154+ } else {
155+ log:: info!(
156+ "Flow deleted successfully id={} deleted_keys={}" ,
157+ id,
158+ deleted_count
159+ ) ;
160+ }
111161 }
112162 Data :: UpdatedFlow ( flow) => {
113163 log:: info!( "Updating the Flow with the id: {}" , & flow. flow_id) ;
@@ -152,8 +202,22 @@ impl SagittariusFlowClient {
152202 }
153203 }
154204 Data :: ModuleConfigurations ( action_configurations) => {
155- if let Err ( err) = self . action_config_tx . send ( action_configurations) {
156- log:: warn!( "No action configuration receivers available: {:?}" , err) ;
205+ let ( project_count, config_count) = module_config_stats ( & action_configurations) ;
206+ log:: debug!(
207+ "Received module configurations from flow stream module_identifier={} project_count={} config_count={}" ,
208+ action_configurations. module_identifier,
209+ project_count,
210+ config_count
211+ ) ;
212+
213+ match self . action_config_tx . send ( action_configurations) {
214+ Ok ( receiver_count) => log:: debug!(
215+ "Broadcasted module configurations to action forwarders receiver_count={}" ,
216+ receiver_count
217+ ) ,
218+ Err ( err) => {
219+ log:: warn!( "No action configuration receivers available: {:?}" , err) ;
220+ }
157221 }
158222 }
159223 }
0 commit comments