File tree Expand file tree Collapse file tree 1 file changed +16
-8
lines changed
services/consumer/src/executor Expand file tree Collapse file tree 1 file changed +16
-8
lines changed Original file line number Diff line number Diff line change @@ -90,16 +90,24 @@ impl BlockExecutor {
90
90
self . concurrent_tasks
91
91
) ;
92
92
let queue = NatsQueue :: BlockImporter ( self . message_broker . clone ( ) ) ;
93
+ let mut active_tasks = 0 ;
94
+ let mut join_set = JoinSet :: new ( ) ;
93
95
94
96
while !token. is_cancelled ( ) {
95
- let mut messages = queue. subscribe ( self . concurrent_tasks ) . await ?;
96
- let mut join_set = JoinSet :: new ( ) ;
97
- while let Some ( msg) = messages. next ( ) . await {
98
- let msg = msg?;
99
- self . spawn_processing_tasks ( msg, & mut join_set) . await ?;
100
- }
101
- while let Some ( result) = join_set. join_next ( ) . await {
102
- result??;
97
+ tracing:: info!( "Active tasks: {}" , active_tasks) ;
98
+ let query_tasks = ( self . concurrent_tasks - active_tasks) . min ( 1 ) ;
99
+ tokio:: select! {
100
+ msg_result = queue. subscribe( query_tasks) => {
101
+ let mut messages = msg_result?;
102
+ while let Some ( msg) = messages. next( ) . await {
103
+ active_tasks += 1 ;
104
+ self . spawn_processing_tasks( msg?, & mut join_set)
105
+ . await ?;
106
+ }
107
+ }
108
+ Some ( _) = join_set. join_next( ) => {
109
+ active_tasks -= 1 ;
110
+ }
103
111
}
104
112
}
105
113
You can’t perform that action at this time.
0 commit comments