From c6e3b14f940a5743ca6fec1ec9d1e5dc50e2d88d Mon Sep 17 00:00:00 2001 From: Gurjot Kaur <88080236+gurjotkaur20@users.noreply.github.com> Date: Sun, 18 Feb 2024 15:33:37 +0530 Subject: [PATCH] fix: retention cleanup on server startup (#662) fixes #660 --- 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 e7aa4b34b..161505e5e 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") }