Skip to content

Commit a145daa

Browse files
committed
Move getting the context to inside the cron loop
1 parent dbfe582 commit a145daa

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

site/src/job_queue.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,18 @@ async fn cron_enqueue_jobs(site_ctxt: &Arc<SiteCtxt>) {
4141

4242
/// Entry point for the cron
4343
pub async fn cron_main(site_ctxt: Arc<RwLock<Option<Arc<SiteCtxt>>>>, seconds: u64) {
44-
let ctxt = site_ctxt.clone();
4544
let mut interval = time::interval(Duration::from_secs(seconds));
45+
let ctxt = site_ctxt.clone();
46+
47+
loop {
48+
interval.tick().await;
4649

47-
if let Some(ctxt_clone) = {
48-
let guard = ctxt.read();
49-
guard.as_ref().cloned()
50-
} {
51-
loop {
50+
if let Some(ctxt_clone) = {
51+
let guard = ctxt.read();
52+
guard.as_ref().cloned()
53+
} {
5254
cron_enqueue_jobs(&ctxt_clone).await;
53-
interval.tick().await;
54-
println!("Cron job executed at: {:?}", std::time::SystemTime::now());
55+
log::info!("Cron job executed at: {:?}", std::time::SystemTime::now());
5556
}
5657
}
5758
}

0 commit comments

Comments
 (0)