Skip to content

Commit a0b3e7b

Browse files
committed
Improve comments and nomenclature in monitoring logic
1 parent 818e640 commit a0b3e7b

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/bin/monitor.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,30 @@ use diesel::prelude::*;
1414
fn main() -> Result<(), Error> {
1515
let conn = db::connect_now()?;
1616

17-
check_stalled_background_jobs(&conn)?;
17+
check_failing_background_jobs(&conn)?;
1818
check_stalled_update_downloads(&conn)?;
1919
check_spam_attack(&conn)?;
2020
Ok(())
2121
}
2222

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> {
2532
use cargo_registry::schema::background_jobs::dsl::*;
2633
use diesel::dsl::*;
2734
use diesel::sql_types::Integer;
2835

2936
const EVENT_KEY: &str = "background_jobs";
3037

31-
println!("Checking for stalled background jobs");
38+
println!("Checking for failed background jobs");
3239

40+
// Max job execution time in minutes
3341
let max_job_time = dotenv::var("MAX_JOB_TIME")
3442
.map(|s| s.parse::<i32>().unwrap())
3543
.unwrap_or(15);
@@ -70,6 +78,7 @@ fn check_stalled_update_downloads(conn: &PgConnection) -> Result<(), Error> {
7078

7179
println!("Checking for stalled background jobs");
7280

81+
// Max job execution time in minutes
7382
let max_job_time = dotenv::var("MONITOR_MAX_UPDATE_DOWNLOADS_TIME")
7483
.map(|s| s.parse::<u32>().unwrap() as i64)
7584
.unwrap_or(120);

0 commit comments

Comments
 (0)