diff --git a/quickpeep_raker/src/raking/task.rs b/quickpeep_raker/src/raking/task.rs index 82d55c8..d784f2a 100644 --- a/quickpeep_raker/src/raking/task.rs +++ b/quickpeep_raker/src/raking/task.rs @@ -78,7 +78,7 @@ pub struct TaskContext { impl TaskContext { pub async fn run(mut self) -> anyhow::Result<()> { // Get a domain to process - while !self.graceful_stop.load(Ordering::Relaxed) { + while !self.graceful_stop.load(Ordering::SeqCst) { let domain = { let txn = self.store.ro_txn()?; txn.acquire_random_active_domain(self.busy_domains.clone())? @@ -196,7 +196,17 @@ impl TaskContext { if let Some(wait_until) = wait_until.take() { // Sleep to respect a crawl-delay - tokio::time::sleep_until(wait_until).await; + tokio::select! { + _ = tokio::time::sleep_until(wait_until) => { + + } + _ = self.notify.notified() => { + if self.graceful_stop.load(Ordering::SeqCst) { + // It's time to shut down + break; + } + } + }; } let delay = if let Some(robot_rules) = current_robot_rules.as_ref() {