Skip to content

Commit

Permalink
feat(backend): Add one simple retry on Unknown
Browse files Browse the repository at this point in the history
  • Loading branch information
amaury1093 committed Dec 18, 2023
1 parent d4b5ef9 commit fcffc1a
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
target
**/*.rs.bk
.DS_Store
private

# Output when debugging Hotmail password recovery using a headless browser.
hotmail.jpeg
Expand Down
5 changes: 1 addition & 4 deletions backend/src/sentry_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,7 @@ fn error(err: SentryError, result: &CheckEmailOutput) {
level: Level::Error,
environment: Some("production".into()),
release: Some(CARGO_PKG_VERSION.into()),
message: Some(redact(
format!("{result:#?}").as_str(),
&result.syntax.username,
)),
message: Some(format!("{result:#?}")),
server_name: get_backend_name(),
transaction: Some(format!("check_email:{}", result.syntax.domain)),
..Default::default()
Expand Down
16 changes: 14 additions & 2 deletions backend/src/worker/check_email.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

use check_if_email_exists::LOG_TARGET;
use check_if_email_exists::{CheckEmailInput, CheckEmailOutput};
use check_if_email_exists::{Reachable, LOG_TARGET};
use lapin::message::Delivery;
use lapin::{options::*, BasicProperties, Channel};
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -80,6 +80,8 @@ pub async fn process_check_email(
debug!(target: LOG_TARGET, reply_to=?reply_to, correlation_id=?correlation_id, "Sent reply")
}

let (email, is_reachable) = (output.input.to_owned(), output.is_reachable.clone());

// Check if we have a webhook to send the output to.
if let Some(webhook) = payload.webhook {
let webhook_output = WebhookOutput {
Expand All @@ -100,7 +102,17 @@ pub async fn process_check_email(
info!(target: LOG_TARGET, email=?webhook_output.output.input, is_reachable=?webhook_output.output.is_reachable, "Finished check");
}

delivery.ack(BasicAckOptions::default()).await?;
// If is_reachable is unknown, then we requeue the message, but only once.
// We might want to add a requeue counter in the future, see:
// https://stackoverflow.com/questions/25226080/rabbitmq-how-to-requeue-message-with-counter
if is_reachable == Reachable::Unknown && !delivery.redelivered {
delivery
.reject(BasicRejectOptions { requeue: true })
.await?;
info!(target: LOG_TARGET, email=?email, "Requeued message");
} else {
delivery.ack(BasicAckOptions::default()).await?;
}

Ok(())
}
2 changes: 1 addition & 1 deletion core/src/util/input_output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ impl CheckEmailInput {

/// An enum to describe how confident we are that the recipient address is
/// real.
#[derive(Debug, Eq, PartialEq, Deserialize, Serialize)]
#[derive(Debug, Clone, Eq, PartialEq, Deserialize, Serialize)]
#[serde(rename_all = "lowercase")]
pub enum Reachable {
/// The email is safe to send.
Expand Down

0 comments on commit fcffc1a

Please sign in to comment.