small rewrite
This commit is contained in:
parent
a8e33383f4
commit
14b420d9df
1 changed files with 35 additions and 29 deletions
|
@ -28,6 +28,9 @@ const INCOMING_WATCH_SK: &str = "watch";
|
||||||
// lost the lock.
|
// lost the lock.
|
||||||
const LOCK_DURATION: Duration = Duration::from_secs(300);
|
const LOCK_DURATION: Duration = Duration::from_secs(300);
|
||||||
|
|
||||||
|
// In addition to checking when notified, also check for new mail every 10 minutes
|
||||||
|
const MAIL_CHECK_INTERVAL: Duration = Duration::from_secs(600);
|
||||||
|
|
||||||
pub async fn incoming_mail_watch_process(
|
pub async fn incoming_mail_watch_process(
|
||||||
user: Weak<User>,
|
user: Weak<User>,
|
||||||
creds: Credentials,
|
creds: Credentials,
|
||||||
|
@ -71,7 +74,7 @@ async fn incoming_mail_watch_process_internal(
|
||||||
|
|
||||||
tokio::select! {
|
tokio::select! {
|
||||||
cv = wait_new_mail => Some(cv.causality),
|
cv = wait_new_mail => Some(cv.causality),
|
||||||
_ = tokio::time::sleep(Duration::from_secs(300)) => prev_ct.take(),
|
_ = tokio::time::sleep(MAIL_CHECK_INTERVAL) => prev_ct.clone(),
|
||||||
_ = lock_held.changed() => None,
|
_ = lock_held.changed() => None,
|
||||||
_ = rx_inbox_id.changed() => None,
|
_ = rx_inbox_id.changed() => None,
|
||||||
}
|
}
|
||||||
|
@ -83,7 +86,13 @@ async fn incoming_mail_watch_process_internal(
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some(user) = Weak::upgrade(&user) {
|
let user = match Weak::upgrade(&user) {
|
||||||
|
Some(user) => user,
|
||||||
|
None => {
|
||||||
|
info!("User no longer available, exiting incoming loop.");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
};
|
||||||
info!("User still available");
|
info!("User still available");
|
||||||
|
|
||||||
// If INBOX no longer is same mailbox, open new mailbox
|
// If INBOX no longer is same mailbox, open new mailbox
|
||||||
|
@ -98,6 +107,7 @@ async fn incoming_mail_watch_process_internal(
|
||||||
inbox = None;
|
inbox = None;
|
||||||
error!("Error when opening inbox ({}): {}", id, e);
|
error!("Error when opening inbox ({}): {}", id, e);
|
||||||
tokio::time::sleep(Duration::from_secs(30)).await;
|
tokio::time::sleep(Duration::from_secs(30)).await;
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -116,10 +126,6 @@ async fn incoming_mail_watch_process_internal(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
info!("User no longer available, exiting incoming loop.");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
drop(rx_inbox_id);
|
drop(rx_inbox_id);
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
Loading…
Reference in a new issue