@@ -14,22 +14,30 @@ use diesel::prelude::*;
14
14
fn main ( ) -> Result < ( ) , Error > {
15
15
let conn = db:: connect_now ( ) ?;
16
16
17
- check_stalled_background_jobs ( & conn) ?;
17
+ check_failing_background_jobs ( & conn) ?;
18
18
check_stalled_update_downloads ( & conn) ?;
19
19
check_spam_attack ( & conn) ?;
20
20
Ok ( ( ) )
21
21
}
22
22
23
- /// Check for old background jobs that are not currently running
24
- fn check_stalled_background_jobs ( conn : & PgConnection ) -> Result < ( ) , Error > {
23
+ /// Check for old background jobs that are not currently running.
24
+ ///
25
+ /// This check includes `skip_locked` in the query and will only trigger on
26
+ /// enqueued jobs that have attempted to run and have failed (and are in the
27
+ /// queue awaiting a retry).
28
+ ///
29
+ /// Within the default 15 minute time, a job should have already had several
30
+ /// failed retry attempts.
31
+ fn check_failing_background_jobs ( conn : & PgConnection ) -> Result < ( ) , Error > {
25
32
use cargo_registry:: schema:: background_jobs:: dsl:: * ;
26
33
use diesel:: dsl:: * ;
27
34
use diesel:: sql_types:: Integer ;
28
35
29
36
const EVENT_KEY : & str = "background_jobs" ;
30
37
31
- println ! ( "Checking for stalled background jobs" ) ;
38
+ println ! ( "Checking for failed background jobs" ) ;
32
39
40
+ // Max job execution time in minutes
33
41
let max_job_time = dotenv:: var ( "MAX_JOB_TIME" )
34
42
. map ( |s| s. parse :: < i32 > ( ) . unwrap ( ) )
35
43
. unwrap_or ( 15 ) ;
@@ -70,6 +78,7 @@ fn check_stalled_update_downloads(conn: &PgConnection) -> Result<(), Error> {
70
78
71
79
println ! ( "Checking for stalled background jobs" ) ;
72
80
81
+ // Max job execution time in minutes
73
82
let max_job_time = dotenv:: var ( "MONITOR_MAX_UPDATE_DOWNLOADS_TIME" )
74
83
. map ( |s| s. parse :: < u32 > ( ) . unwrap ( ) as i64 )
75
84
. unwrap_or ( 120 ) ;
0 commit comments