Skip to content

Commit 408867d

Browse files
committed
jobs/send_publish_notifications: Add logging calls
1 parent 035cae8 commit 408867d

File tree

1 file changed

+33
-8
lines changed

1 file changed

+33
-8
lines changed

src/worker/jobs/send_publish_notifications.rs

Lines changed: 33 additions & 8 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,9 +55,11 @@ 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.
56-
spawn_blocking(move || {
62+
let num_sent = spawn_blocking(move || {
5763
let results = recipients
5864
.into_iter()
5965
.map(|(ref recipient, email_address)| {
@@ -80,21 +86,40 @@ 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")),
94-
}
96+
Ok::<_, anyhow::Error>(results.iter().filter(|result| result.is_ok()).count())
9597
})
9698
.await?;
9799

100+
// Check if *none* of the emails succeeded to send, in which case we
101+
// consider the job failed and worth retrying.
102+
if num_sent == 0 {
103+
warn!(
104+
"Failed to send publish notifications for {}@{}",
105+
publish_details.krate, publish_details.version
106+
);
107+
108+
return Err(anyhow!("Failed to send publish notifications"));
109+
}
110+
111+
if num_sent == num_recipients {
112+
info!(
113+
"Sent {num_sent} publish notifications for {}@{}",
114+
publish_details.krate, publish_details.version
115+
);
116+
} else {
117+
warn!(
118+
"Sent only {num_sent} of {num_recipients} publish notifications for {}@{}",
119+
publish_details.krate, publish_details.version
120+
);
121+
}
122+
98123
Ok(())
99124
}
100125
}

0 commit comments

Comments
 (0)