Skip to content

Commit 72f9568

Browse files
authored
jobs/send_publish_notifications: Add logging calls (#9357)
1 parent b6d434e commit 72f9568

File tree

1 file changed

+34
-9
lines changed

1 file changed

+34
-9
lines changed

src/worker/jobs/send_publish_notifications.rs

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,14 @@ impl BackgroundJob for SendPublishNotificationsJob {
2929
type Context = Arc<Environment>;
3030

3131
async fn run(&self, ctx: Self::Context) -> anyhow::Result<()> {
32+
let version_id = self.version_id;
33+
34+
info!("Sending publish notifications for version {version_id}…");
35+
3236
let mut conn = ctx.deadpool.get().await?;
3337

3438
// Get crate name, version and other publish details
35-
let publish_details = PublishDetails::for_version(self.version_id, &mut conn).await?;
39+
let publish_details = PublishDetails::for_version(version_id, &mut conn).await?;
3640

3741
let publish_time = publish_details
3842
.publish_time
@@ -51,6 +55,8 @@ impl BackgroundJob for SendPublishNotificationsJob {
5155
.load::<(String, String)>(&mut conn)
5256
.await?;
5357

58+
let num_recipients = recipients.len();
59+
5460
// Sending emails is currently a blocking operation, so we have to use
5561
// `spawn_blocking()` to run it in a separate thread.
5662
spawn_blocking(move || {
@@ -80,22 +86,41 @@ impl BackgroundJob for SendPublishNotificationsJob {
8086
publisher_info,
8187
};
8288

89+
debug!("Sending publish notification for {krate}@{version} to {email_address}…");
8390
ctx.emails.send(&email_address, email).inspect_err(|err| {
8491
warn!("Failed to send publish notification for {krate}@{version} to {email_address}: {err}")
8592
})
8693
})
8794
.collect::<Vec<_>>();
8895

89-
// Check if any of the emails succeeded to send, in which case we
90-
// consider the job successful enough and not worth retrying.
91-
match results.iter().any(|result| result.is_ok()) {
92-
true => Ok(()),
93-
false => Err(anyhow!("Failed to send publish notifications")),
96+
let num_sent = results.iter().filter(|result| result.is_ok()).count();
97+
98+
// Check if *none* of the emails succeeded to send, in which case we
99+
// consider the job failed and worth retrying.
100+
if num_sent == 0 {
101+
warn!(
102+
"Failed to send publish notifications for {}@{}",
103+
publish_details.krate, publish_details.version
104+
);
105+
106+
return Err(anyhow!("Failed to send publish notifications"));
107+
}
108+
109+
if num_sent == num_recipients {
110+
info!(
111+
"Sent {num_sent} publish notifications for {}@{}",
112+
publish_details.krate, publish_details.version
113+
);
114+
} else {
115+
warn!(
116+
"Sent only {num_sent} of {num_recipients} publish notifications for {}@{}",
117+
publish_details.krate, publish_details.version
118+
);
94119
}
95-
})
96-
.await?;
97120

98-
Ok(())
121+
Ok(())
122+
})
123+
.await
99124
}
100125
}
101126

0 commit comments

Comments
 (0)