Skip to content

Commit 807a570

Browse files
authored
worker/jobs/expiry_notification: Reduce log level for missing email addresses (#8658)
Ideally, we wouldn't have users without associated email addresses, but for some reason we currently appear to have such cases. Instead of treating this as a hard error for the token expiry notification we can log it with `INFO` level and mark the token as processed even if no notification has been sent out.
1 parent cd9806a commit 807a570

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

src/worker/jobs/expiry_notification.rs

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -77,17 +77,21 @@ fn handle_expiring_token(
7777
let user = User::find(conn, token.user_id)?;
7878

7979
debug!("Looking up email address for user {}…", user.id);
80-
let recipient = user
81-
.email(conn)?
82-
.ok_or_else(|| anyhow!("No address found"))?;
83-
84-
debug!("Sending expiry notification to {}…", recipient);
85-
let email = ExpiryNotificationEmail {
86-
name: &user.gh_login,
87-
token_name: &token.name,
88-
expiry_date: token.expired_at.unwrap().and_utc(),
89-
};
90-
emails.send(&recipient, email)?;
80+
let recipient = user.email(conn)?;
81+
if let Some(recipient) = recipient {
82+
debug!("Sending expiry notification to {}…", recipient);
83+
let email = ExpiryNotificationEmail {
84+
name: &user.gh_login,
85+
token_name: &token.name,
86+
expiry_date: token.expired_at.unwrap().and_utc(),
87+
};
88+
emails.send(&recipient, email)?;
89+
} else {
90+
info!(
91+
"User {} has no email address set. Skipping expiry notification.",
92+
user.id
93+
);
94+
}
9195

9296
// Update the token to prevent duplicate notifications.
9397
debug!("Marking token {} as notified…", token.id);

0 commit comments

Comments
 (0)