refactor: extract daemon task spawning
This commit is contained in:
parent
fd3651b25f
commit
e7502a7237
3 changed files with 43 additions and 35 deletions
37
crates/geth-node/src/daemon.rs
Normal file
37
crates/geth-node/src/daemon.rs
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
//! Daemon task orchestration helpers.
|
||||
|
||||
use crate::LocalNode;
|
||||
use geth_iroh::GethIrohEndpoint;
|
||||
use std::time::Duration;
|
||||
|
||||
pub(crate) fn spawn_iroh_control_accept_loop(node: LocalNode, endpoint: GethIrohEndpoint) {
|
||||
let raw_endpoint = endpoint.endpoint();
|
||||
tokio::spawn(async move {
|
||||
tracing::debug!("iroh accept loop started");
|
||||
while let Some(incoming) = raw_endpoint.accept().await {
|
||||
tracing::debug!("iroh incoming connection accepted by endpoint loop");
|
||||
let node = node.clone();
|
||||
tokio::spawn(async move {
|
||||
if let Err(error) = super::handle_iroh_control_connection(node, incoming).await {
|
||||
tracing::warn!(%error, "iroh control request failed");
|
||||
}
|
||||
});
|
||||
}
|
||||
tracing::debug!("iroh accept loop ended");
|
||||
});
|
||||
}
|
||||
|
||||
pub(crate) fn spawn_background_live_sync(node: LocalNode, interval_duration: Duration) {
|
||||
tokio::spawn(async move {
|
||||
if let Err(error) = super::run_live_sync_once(&node).await {
|
||||
tracing::debug!(%error, "initial live sync tick failed");
|
||||
}
|
||||
let mut interval = tokio::time::interval(interval_duration);
|
||||
loop {
|
||||
interval.tick().await;
|
||||
if let Err(error) = super::run_live_sync_once(&node).await {
|
||||
tracing::debug!(%error, "live sync tick failed");
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
Loading…
Reference in a new issue