@@ -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,9 +55,11 @@ 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
- spawn_blocking ( move || {
62
+ let num_sent = spawn_blocking ( move || {
57
63
let results = recipients
58
64
. into_iter ( )
59
65
. map ( |( ref recipient, email_address) | {
@@ -80,21 +86,40 @@ 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" ) ) ,
94
- }
96
+ Ok :: < _ , anyhow:: Error > ( results. iter ( ) . filter ( |result| result. is_ok ( ) ) . count ( ) )
95
97
} )
96
98
. await ?;
97
99
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
+
98
123
Ok ( ( ) )
99
124
}
100
125
}
0 commit comments