2023-11-29 23:43:53 +00:00
|
|
|
use tracing::{error, trace, Instrument};
|
2023-11-25 15:15:16 +00:00
|
|
|
|
2023-12-03 12:14:50 +00:00
|
|
|
/// Spawns a future with tracing instrumentation.
|
2023-11-25 15:15:16 +00:00
|
|
|
pub fn spawn(
|
|
|
|
|
span: tracing::Span,
|
|
|
|
|
fut: impl std::future::Future<Output = anyhow::Result<()>> + Send + 'static,
|
|
|
|
|
) -> tokio::task::JoinHandle<()> {
|
|
|
|
|
let fut = async move {
|
|
|
|
|
trace!("started");
|
2023-12-01 10:48:16 +00:00
|
|
|
tokio::pin!(fut);
|
|
|
|
|
let mut trace_interval = tokio::time::interval(std::time::Duration::from_secs(5));
|
|
|
|
|
|
|
|
|
|
loop {
|
|
|
|
|
tokio::select! {
|
|
|
|
|
_ = trace_interval.tick() => {
|
|
|
|
|
trace!("still running");
|
|
|
|
|
},
|
|
|
|
|
r = &mut fut => {
|
|
|
|
|
match r {
|
|
|
|
|
Ok(_) => {
|
|
|
|
|
trace!("finished");
|
|
|
|
|
}
|
|
|
|
|
Err(e) => {
|
|
|
|
|
error!("finished with error: {:#}", e)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
2023-11-25 15:15:16 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
.instrument(span);
|
|
|
|
|
tokio::task::spawn(fut)
|
|
|
|
|
}
|