Connectivity view: Only set smtp to "connected" if the last message was actually sent (#2541)

fix #2539

It's always a bit ambiguous which function should do set_err or set last_send_error, I used this rule here:

If some code returns Status::RetryLater, then it sets last_send_error, because Status::RetryLater means that the user won't see the error directly on the message (if we returned Status::Failed(Err(_)), then the message would be shown as failed to the user) Also, smtp_send always sets last_send_error because, well, sending just failed or succeeded.

Also, remove unused field pending_error.
This commit is contained in:
Hocuri
2021-08-09 12:31:33 +02:00
committed by GitHub
parent 20bf41b4e6
commit faab61b0d4
3 changed files with 24 additions and 21 deletions

View File

@@ -148,7 +148,6 @@ pub struct Job {
pub added_timestamp: i64,
pub tries: u32,
pub param: Params,
pub pending_error: Option<String>,
}
impl fmt::Display for Job {
@@ -169,7 +168,6 @@ impl Job {
added_timestamp: timestamp,
tries: 0,
param,
pending_error: None,
}
}
@@ -251,12 +249,13 @@ impl Job {
smtp.connectivity.set_working(context).await;
let status = match smtp.send(context, recipients, message, job_id).await {
let send_result = smtp.send(context, recipients, message, job_id).await;
smtp.last_send_error = send_result.as_ref().err().map(|e| e.to_string());
let status = match send_result {
Err(crate::smtp::send::Error::SmtpSend(err)) => {
// Remote error, retry later.
warn!(context, "SMTP failed to send: {:?}", &err);
smtp.connectivity.set_err(context, &err).await;
self.pending_error = Some(err.to_string());
let res = match err {
async_smtp::smtp::error::Error::Permanent(ref response) => {
@@ -365,6 +364,7 @@ impl Job {
// SMTP server, if not yet done
if let Err(err) = smtp.connect_configured(context).await {
warn!(context, "SMTP connection failure: {:?}", err);
smtp.last_send_error = Some(format!("SMTP connection failure: {:#}", err));
return Status::RetryLater;
}
@@ -407,6 +407,8 @@ impl Job {
}
Err(err) => {
warn!(context, "failed to check message existence: {:?}", err);
smtp.last_send_error =
Some(format!("failed to check message existence: {:#}", err));
return Status::RetryLater;
}
}
@@ -521,6 +523,7 @@ impl Job {
// connect to SMTP server, if not yet done
if let Err(err) = smtp.connect_configured(context).await {
warn!(context, "SMTP connection failure: {:?}", err);
smtp.last_send_error = Some(err.to_string());
return Status::RetryLater;
}
@@ -1321,7 +1324,6 @@ LIMIT 1;
added_timestamp: row.get("added_timestamp")?,
tries: row.get("tries")?,
param: row.get::<_, String>("param")?.parse().unwrap_or_default(),
pending_error: None,
};
Ok(job)