feat: add next run time
All checks were successful
continuous-integration/drone Build is passing

This commit is contained in:
2025-03-27 13:01:36 +01:00
parent 1f1f566c62
commit 785a1f8739
3 changed files with 264 additions and 137 deletions

View File

@@ -8,6 +8,7 @@ edition = "2021"
[dependencies]
anyhow.workspace = true
async-trait = "0.1.81"
chrono = "0.4.40"
thiserror = "2.0.0"
tokio.workspace = true
tokio-util = "0.7.11"

View File

@@ -1,6 +1,7 @@
use std::{sync::Arc, time::Duration};
use async_trait::async_trait;
use chrono::{DateTime, Local};
use std::future::Future;
use tokio::time;
use tokio_util::sync::CancellationToken;
@@ -33,7 +34,6 @@ where
let drifter = drifter.clone();
async move {
let mut wait = interval;
let start = std::time::Instant::now();
tracing::debug!("running job");
@@ -44,7 +44,7 @@ where
}
let elapsed = start.elapsed();
wait = interval.saturating_sub(elapsed);
let mut wait = interval.saturating_sub(elapsed);
tracing::debug!(
"job took: {}ms, waiting: {}ms for next run",
elapsed.as_millis(),
@@ -74,7 +74,11 @@ where
let elapsed = start.elapsed();
wait = interval.saturating_sub(elapsed);
tracing::debug!("job took: {}ms, waiting: {}ms for next run", elapsed.as_millis(), wait.as_millis());
let now: DateTime<Local> = Local::now();
let next: Option<DateTime<Local>> = std::time::SystemTime::now().checked_add(wait).map(|next| next.into());
tracing::debug!(?now, ?next, "job took: {}ms, waiting: {}ms for next run", elapsed.as_millis(), wait.as_millis() );
}
}