small rewrite

This commit is contained in:
Alex 2022-07-01 19:41:29 +02:00
parent a8e33383f4
commit 14b420d9df
Signed by: lx
GPG Key ID: 0E496D15096376BE
1 changed files with 35 additions and 29 deletions

View File

@ -28,6 +28,9 @@ const INCOMING_WATCH_SK: &str = "watch";
// lost the lock.
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(
user: Weak<User>,
creds: Credentials,
@ -71,7 +74,7 @@ async fn incoming_mail_watch_process_internal(
tokio::select! {
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,
_ = 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");
// If INBOX no longer is same mailbox, open new mailbox
@ -98,6 +107,7 @@ async fn incoming_mail_watch_process_internal(
inbox = None;
error!("Error when opening inbox ({}): {}", id, e);
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);
Ok(())