omni_orchestrator/initialization/
start_peer_discovery.rs

1use colored::Colorize;
2use crate::{CLUSTER_MANAGER, SERVER_CONFIG};
3
4pub fn start_peer_discovery(port: u16) {
5    log::info!("{}", "Starting peer discovery background task".magenta());
6    tokio::task::spawn({
7        let cluster_manager = CLUSTER_MANAGER.clone();
8        let server_config = SERVER_CONFIG.clone();
9        async move {
10            loop {
11                if let Err(e) = cluster_manager
12                    .read()
13                    .await
14                    .discover_peers(&server_config, port)
15                    .await
16                {
17                    log::error!("{}", format!("Failed to discover peers: {e}").red());
18                }
19                tokio::time::sleep(tokio::time::Duration::from_millis(2000)).await;
20            }
21        }
22    });
23}