@@ -16,8 +16,8 @@ use crate::{
16
16
workers:: workflow:: { WorkflowsWorker , WorkflowsWorkerInput , WorkflowsWorkerOutput } ,
17
17
} ;
18
18
19
- /// Number of seconds between refreshing the Kademlia DHT .
20
- const PEER_REFRESH_INTERVAL_SECS : u64 = 30 ;
19
+ /// Number of seconds between refreshing for diagnostic prints .
20
+ const DIAGNOSTIC_REFRESH_INTERVAL_SECS : u64 = 30 ;
21
21
/// Number of seconds between refreshing the available nodes.
22
22
const AVAILABLE_NODES_REFRESH_INTERVAL_SECS : u64 = 30 * 60 ; // 30 minutes
23
23
@@ -123,7 +123,7 @@ impl DriaComputeNode {
123
123
}
124
124
125
125
/// Returns the task count within the channels, `single` and `batch`.
126
- pub fn task_count ( & self ) -> [ usize ; 2 ] {
126
+ pub fn get_active_task_count ( & self ) -> [ usize ; 2 ] {
127
127
[
128
128
self . workflow_single_tx . max_capacity ( ) - self . workflow_single_tx . capacity ( ) ,
129
129
self . workflow_batch_tx . max_capacity ( ) - self . workflow_batch_tx . capacity ( ) ,
@@ -251,9 +251,10 @@ impl DriaComputeNode {
251
251
/// This method is not expected to return until cancellation occurs.
252
252
pub async fn run ( & mut self ) -> Result < ( ) > {
253
253
// prepare durations for sleeps
254
- let peer_refresh_duration = Duration :: from_secs ( PEER_REFRESH_INTERVAL_SECS ) ;
255
- let available_node_refresh_duration =
256
- Duration :: from_secs ( AVAILABLE_NODES_REFRESH_INTERVAL_SECS ) ;
254
+ let mut peer_refresh_interval =
255
+ tokio:: time:: interval ( Duration :: from_secs ( DIAGNOSTIC_REFRESH_INTERVAL_SECS ) ) ;
256
+ let mut available_node_refresh_interval =
257
+ tokio:: time:: interval ( Duration :: from_secs ( AVAILABLE_NODES_REFRESH_INTERVAL_SECS ) ) ;
257
258
258
259
// subscribe to topics
259
260
self . subscribe ( PingpongHandler :: LISTEN_TOPIC ) . await ?;
@@ -264,9 +265,9 @@ impl DriaComputeNode {
264
265
loop {
265
266
tokio:: select! {
266
267
// check peer count every now and then
267
- _ = tokio :: time :: sleep ( peer_refresh_duration ) => self . handle_peer_refresh ( ) . await ,
268
+ _ = peer_refresh_interval . tick ( ) => self . handle_diagnostic_refresh ( ) . await ,
268
269
// available nodes are refreshed every now and then
269
- _ = tokio :: time :: sleep ( available_node_refresh_duration ) => self . handle_available_nodes_refresh( ) . await ,
270
+ _ = available_node_refresh_interval . tick ( ) => self . handle_available_nodes_refresh( ) . await ,
270
271
// a Workflow message to be published is received from the channel
271
272
// this is expected to be sent by the workflow worker
272
273
publish_msg = self . publish_batch_rx. recv( ) => {
@@ -336,11 +337,16 @@ impl DriaComputeNode {
336
337
}
337
338
338
339
/// Peer refresh simply reports the peer count to the user.
339
- async fn handle_peer_refresh ( & self ) {
340
+ async fn handle_diagnostic_refresh ( & self ) {
341
+ // print peer counts
340
342
match self . p2p . peer_counts ( ) . await {
341
343
Ok ( ( mesh, all) ) => log:: info!( "Peer Count (mesh/all): {} / {}" , mesh, all) ,
342
344
Err ( e) => log:: error!( "Error getting peer counts: {:?}" , e) ,
343
345
}
346
+
347
+ // print task counts
348
+ let [ single, batch] = self . get_active_task_count ( ) ;
349
+ log:: info!( "Active Task Count (single/batch): {} / {}" , single, batch) ;
344
350
}
345
351
346
352
/// Updates the local list of available nodes by refreshing it.
0 commit comments