mirror of
https://github.com/chatmail/core.git
synced 2026-04-26 18:06:35 +03:00
better naming, less code
This commit is contained in:
15
src/job.rs
15
src/job.rs
@@ -205,17 +205,12 @@ impl Job {
|
||||
Status::RetryLater
|
||||
}
|
||||
_ => {
|
||||
// if the connection was successfully used more than 60
|
||||
// seconds ago, try an immediate reconnect.
|
||||
let mut res2 = Status::RetryLater;
|
||||
if let Some(secs) = smtp.secs_since_last_success() {
|
||||
if secs > 60 {
|
||||
info!(context, "stale connection? triggering reconnect");
|
||||
res2 = Status::RetryNow;
|
||||
}
|
||||
if smtp.has_maybe_stale_connection() {
|
||||
info!(context, "stale connection? immediately reconnecting");
|
||||
Status::RetryNow
|
||||
} else {
|
||||
Status::RetryLater
|
||||
}
|
||||
|
||||
res2
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -77,13 +77,13 @@ impl Smtp {
|
||||
self.last_success = None;
|
||||
}
|
||||
|
||||
/// Return number of seconds since last success or None if
|
||||
/// no success-time is recorded in this session.
|
||||
pub fn secs_since_last_success(&self) -> Option<u64> {
|
||||
/// Return true if smtp was connected but is not known to
|
||||
/// have been successfully used the last 60 seconds
|
||||
pub fn has_maybe_stale_connection(&self) -> bool {
|
||||
if let Some(last_success) = self.last_success {
|
||||
Some(Instant::now().duration_since(last_success).as_secs())
|
||||
Instant::now().duration_since(last_success).as_secs() > 60
|
||||
} else {
|
||||
None
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user