From 72e284ce2d890c7f1d9118da76af1329332faf0b Mon Sep 17 00:00:00 2001 From: gurjotkaur20 Date: Sat, 17 Feb 2024 17:56:03 +0530 Subject: [PATCH] fix: retention cleanup on server startup --- server/src/storage/retention.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/server/src/storage/retention.rs b/server/src/storage/retention.rs index 82062575a..beb8edd2e 100644 --- a/server/src/storage/retention.rs +++ b/server/src/storage/retention.rs @@ -83,9 +83,15 @@ pub fn init_scheduler() { } }; + // Execute once on startup + thread::spawn(move || { + let rt = async_runtime(); + rt.block_on(func()); + }); + scheduler.every(1.day()).at("00:00").run(func); - let handler = thread::spawn(|| { + let scheduler_handler = thread::spawn(|| { let rt = async_runtime(); rt.block_on(async move { loop { @@ -95,7 +101,7 @@ pub fn init_scheduler() { }); }); - *SCHEDULER_HANDLER.lock().unwrap() = Some(handler); + *SCHEDULER_HANDLER.lock().unwrap() = Some(scheduler_handler); log::info!("Scheduler is initialized") }