Shut down faster (don't wait for crawl delays)

This commit is contained in:
Olivier 'reivilibre' 2022-03-21 19:39:31 +00:00
parent a60ace0482
commit 806192fab5
1 changed files with 12 additions and 2 deletions

View File

@ -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() {