-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
88 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
use crate::{ | ||
controllers::public::nodex_receive::ConnectionRepository, network::Network, services::hub::Hub, | ||
}; | ||
use std::sync::{atomic::AtomicBool, Arc}; | ||
|
||
pub async fn handler( | ||
shutdown_marker: Arc<AtomicBool>, | ||
connection_repository: ConnectionRepository, | ||
) { | ||
let network = Network::new(); | ||
|
||
let heartbeat_interval_sec = if let Some(heartbeat_interval_sec) = network.get_heartbeat() { | ||
heartbeat_interval_sec | ||
} else { | ||
log::info!("heartbeat is disabled"); | ||
return; | ||
}; | ||
|
||
let project_did = network.root.project_did.expect("project_did is not set"); | ||
|
||
log::info!("heartbeat task is started"); | ||
|
||
let mut interval = | ||
tokio::time::interval(std::time::Duration::from_secs(heartbeat_interval_sec)); | ||
let hub = Hub::new(); | ||
|
||
while !shutdown_marker.load(std::sync::atomic::Ordering::SeqCst) { | ||
interval.tick().await; | ||
|
||
let is_active = connection_repository.connection_count() > 0; | ||
|
||
if let Err(e) = hub.heartbeat(&project_did, is_active).await { | ||
log::error!("failed to send heartbeat: {:?}", e); | ||
} | ||
} | ||
|
||
log::info!("heartbeat task is stopped"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
use serde_json::Value; | ||
use tokio::sync::oneshot; | ||
|
||
pub mod heartbeat; | ||
pub mod receiver; | ||
pub mod sender; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters