mirror of
https://github.com/chatmail/core.git
synced 2026-05-20 07:16:31 +03:00
feat: Grow sleep durations on errors in Imap::fake_idle() (#4424)
This commit is contained in:
@@ -135,10 +135,8 @@ impl Imap {
|
|||||||
};
|
};
|
||||||
info!(context, "IMAP-fake-IDLEing folder={:?}", watch_folder);
|
info!(context, "IMAP-fake-IDLEing folder={:?}", watch_folder);
|
||||||
|
|
||||||
// check every minute if there are new messages
|
const TIMEOUT_INIT_MS: u64 = 60_000;
|
||||||
// TODO: grow sleep durations / make them more flexible
|
let mut timeout_ms: u64 = TIMEOUT_INIT_MS;
|
||||||
let mut interval = tokio::time::interval(Duration::from_secs(60));
|
|
||||||
|
|
||||||
enum Event {
|
enum Event {
|
||||||
Tick,
|
Tick,
|
||||||
Interrupt,
|
Interrupt,
|
||||||
@@ -146,6 +144,12 @@ impl Imap {
|
|||||||
// loop until we are interrupted or if we fetched something
|
// loop until we are interrupted or if we fetched something
|
||||||
loop {
|
loop {
|
||||||
use futures::future::FutureExt;
|
use futures::future::FutureExt;
|
||||||
|
use rand::Rng;
|
||||||
|
|
||||||
|
let mut interval = tokio::time::interval(Duration::from_millis(timeout_ms));
|
||||||
|
timeout_ms = timeout_ms
|
||||||
|
.saturating_add(rand::thread_rng().gen_range((timeout_ms / 2)..=timeout_ms));
|
||||||
|
interval.tick().await; // The first tick completes immediately.
|
||||||
match interval
|
match interval
|
||||||
.tick()
|
.tick()
|
||||||
.map(|_| Event::Tick)
|
.map(|_| Event::Tick)
|
||||||
@@ -188,6 +192,7 @@ impl Imap {
|
|||||||
{
|
{
|
||||||
Ok(res) => {
|
Ok(res) => {
|
||||||
info!(context, "fetch_new_messages returned {:?}", res);
|
info!(context, "fetch_new_messages returned {:?}", res);
|
||||||
|
timeout_ms = TIMEOUT_INIT_MS;
|
||||||
if res {
|
if res {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user