better practice for displaying next run date

This commit is contained in:
blek 2023-10-12 22:12:40 +10:00
parent 655fe8a1d5
commit 7c57472cb4
Signed by: blek
GPG Key ID: 14546221E3595D0C
1 changed files with 10 additions and 12 deletions

View File

@ -12,11 +12,11 @@ pub fn redis_conn(env: env::Env) -> Result<redis::Client, redis::RedisError> {
}
#[derive(Debug, Clone)]
#[allow(dead_code)]
enum CleanResult {
Skip,
#[allow(dead_code)]
Break,
Ok
ScheduleNext(chrono::DateTime<chrono::Local>)
}
async fn clean(env: env::Env, state: State) -> CleanResult {
@ -27,21 +27,13 @@ async fn clean(env: env::Env, state: State) -> CleanResult {
let res = clean::clean(state.clone()).await;
if res.is_err() {
log::error!("Error while cleaning: {}", res.unwrap_err());
log::error!("Retrying in {}", std::env::var("CLEAN_ERRDEL").unwrap());
log::debug!("Next clean will run at {}", chrono::Local::now() + env.clean_errdel);
tokio::time::sleep(envy.clean_errdel).await;
return CleanResult::Skip;
return CleanResult::ScheduleNext(chrono::Local::now() + env.clean_errdel);
}
#[cfg(debug_assertions)] {
log::debug!("Cleaned successfully");
log::debug!("Next clean is scheduled in {}", std::env::var("CLEAN_DEL").unwrap());
log::debug!("Next clean will run at {}", chrono::Local::now() + env.clean_del);
return CleanResult::ScheduleNext(chrono::Local::now() + env.clean_del);
}
tokio::time::sleep(envy.clean_errdel).await;
CleanResult::Ok
}
#[tokio::main]
@ -72,6 +64,12 @@ async fn main() {
CleanResult::Break => {
break
},
CleanResult::ScheduleNext(next) => {
#[cfg(debug_assertions)] {
log::debug!("Next run is scheduled at {} ({})", next.format("%d-%m-%Y %H:%M:%S"), next.timestamp());
}
tokio::time::sleep((next - chrono::Local::now()).to_std().unwrap()).await;
},
_ => {}
}
}