refine processing of errors and result handling

This commit is contained in:
holger krekel
2020-02-20 00:30:32 +01:00
parent 840e321dd9
commit 4d066b4fd2

View File

@@ -195,31 +195,29 @@ impl Job {
warn!(context, "SMTP failed to send: {}", err); warn!(context, "SMTP failed to send: {}", err);
self.pending_error = Some(err.to_string()); self.pending_error = Some(err.to_string());
let res = match err {
async_smtp::smtp::error::Error::Permanent(_) => {
Status::Finished(Err(format_err!("Permanent SMTP error: {}", err)))
}
async_smtp::smtp::error::Error::Transient(_) => {
// We got a transient 4xx response from SMTP server.
// Give some time until the server-side error maybe goes away.
Status::RetryLater
}
_ => {
// if the connection was successfully used more than 60 // if the connection was successfully used more than 60
// seconds ago, try an immediate reconnect. // seconds ago, try an immediate reconnect.
let mut res = Status::RetryLater; let mut res2 = Status::RetryLater;
if let Some(secs) = smtp.secs_since_last_success() { if let Some(secs) = smtp.secs_since_last_success() {
if secs > 60 { if secs > 60 {
info!( info!(context, "stale connection? triggering reconnect");
context, res2 = Status::RetryNow;
"SMTP connection was stale, triggering immediate reconnect"
);
res = Status::RetryNow;
} }
} }
match err { res2
async_smtp::smtp::error::Error::Permanent(_) => {
res = Status::Finished(Err(format_err!("Permanent SMTP error: {}", err)))
}
async_smtp::smtp::error::Error::Transient(_) => {
// We got a 4xx response from SMTP server.
// Do not retry right now, wait until the error resolves on the server
// side.
res = Status::RetryLater;
}
_ => {}
} }
};
// this clears last_success info // this clears last_success info
smtp.disconnect(); smtp.disconnect();