@@ -29,10 +29,14 @@ impl BackgroundJob for SendPublishNotificationsJob {
29
29
type Context = Arc < Environment > ;
30
30
31
31
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
+
32
36
let mut conn = ctx. deadpool . get ( ) . await ?;
33
37
34
38
// 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 ?;
36
40
37
41
let publish_time = publish_details
38
42
. publish_time
@@ -51,6 +55,8 @@ impl BackgroundJob for SendPublishNotificationsJob {
51
55
. load :: < ( String , String ) > ( & mut conn)
52
56
. await ?;
53
57
58
+ let num_recipients = recipients. len ( ) ;
59
+
54
60
// Sending emails is currently a blocking operation, so we have to use
55
61
// `spawn_blocking()` to run it in a separate thread.
56
62
spawn_blocking ( move || {
@@ -80,22 +86,41 @@ impl BackgroundJob for SendPublishNotificationsJob {
80
86
publisher_info,
81
87
} ;
82
88
89
+ debug ! ( "Sending publish notification for {krate}@{version} to {email_address}…" ) ;
83
90
ctx. emails . send ( & email_address, email) . inspect_err ( |err| {
84
91
warn ! ( "Failed to send publish notification for {krate}@{version} to {email_address}: {err}" )
85
92
} )
86
93
} )
87
94
. collect :: < Vec < _ > > ( ) ;
88
95
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
+ ) ;
94
119
}
95
- } )
96
- . await ?;
97
120
98
- Ok ( ( ) )
121
+ Ok ( ( ) )
122
+ } )
123
+ . await
99
124
}
100
125
}
101
126
0 commit comments