@@ -252,7 +252,10 @@ pub async fn build_queue(
252
252
}
253
253
254
254
/// Enqueue the job into the job_queue
255
- async fn enqueue_next_job ( conn : & mut dyn database:: pool:: Connection ) -> anyhow:: Result < ( ) > {
255
+ async fn enqueue_next_job (
256
+ conn : & mut dyn database:: pool:: Connection ,
257
+ should_add_to_db : bool ,
258
+ ) -> anyhow:: Result < ( ) > {
256
259
// We draw back all completed requests
257
260
let completed: HashSet < String > = conn
258
261
. get_benchmark_requests_by_status ( & [ BenchmarkRequestStatus :: Completed ] )
@@ -265,26 +268,32 @@ async fn enqueue_next_job(conn: &mut dyn database::pool::Connection) -> anyhow::
265
268
266
269
if let Some ( request) = queue. into_iter ( ) . next ( ) {
267
270
if request. status != BenchmarkRequestStatus :: InProgress {
268
- log:: info!( "{:?} would have been marked as InProgress" , request) ;
269
271
// TODO:
270
- // - Uncomment this code
272
+ // - Remove this if condition
271
273
// - Actually enqueue the jobs
272
- // conn.update_benchmark_request_status(&request, BenchmarkRequestStatus::InProgress)
273
- // .await?;
274
+ if !should_add_to_db {
275
+ log:: info!( "{:?} would have been marked as InProgress" , request) ;
276
+ } else {
277
+ conn. update_benchmark_request_status ( & request, BenchmarkRequestStatus :: InProgress )
278
+ . await ?;
279
+ }
274
280
}
275
281
}
276
282
277
283
Ok ( ( ) )
278
284
}
279
285
280
286
/// For queueing jobs, add the jobs you want to queue to this function
281
- async fn cron_enqueue_jobs ( site_ctxt : & Arc < SiteCtxt > ) -> anyhow:: Result < ( ) > {
287
+ async fn cron_enqueue_jobs (
288
+ site_ctxt : & Arc < SiteCtxt > ,
289
+ should_add_to_db : bool ,
290
+ ) -> anyhow:: Result < ( ) > {
282
291
let mut conn = site_ctxt. conn ( ) . await ;
283
292
// Put the master commits into the `benchmark_requests` queue
284
293
create_benchmark_request_master_commits ( site_ctxt, & * conn) . await ?;
285
294
// Put the releases into the `benchmark_requests` queue
286
295
create_benchmark_request_releases ( & * conn) . await ?;
287
- enqueue_next_job ( & mut * conn) . await ?;
296
+ enqueue_next_job ( & mut * conn, should_add_to_db ) . await ?;
288
297
Ok ( ( ) )
289
298
}
290
299
@@ -300,7 +309,7 @@ pub async fn cron_main(site_ctxt: Arc<RwLock<Option<Arc<SiteCtxt>>>>, seconds: u
300
309
let guard = ctxt. read ( ) ;
301
310
guard. as_ref ( ) . cloned ( )
302
311
} {
303
- match cron_enqueue_jobs ( & ctxt_clone) . await {
312
+ match cron_enqueue_jobs ( & ctxt_clone, false ) . await {
304
313
Ok ( _) => log:: info!( "Cron job executed at: {:?}" , std:: time:: SystemTime :: now( ) ) ,
305
314
Err ( e) => log:: error!( "Cron job failed to execute {}" , e) ,
306
315
}
@@ -422,7 +431,7 @@ mod tests {
422
431
run_postgres_test ( |ctx| async {
423
432
let mut db = ctx. db_client ( ) . connection ( ) . await ;
424
433
425
- enqueue_next_job ( & mut * db) . await ?;
434
+ enqueue_next_job ( & mut * db, true ) . await ?;
426
435
427
436
let in_progress = get_in_progress ( & * db) . await ;
428
437
@@ -443,7 +452,7 @@ mod tests {
443
452
444
453
db_insert_requests ( & * db, & [ parent, child] ) . await ;
445
454
446
- enqueue_next_job ( & mut * db) . await ?;
455
+ enqueue_next_job ( & mut * db, true ) . await ?;
447
456
448
457
let in_progress = get_in_progress ( & * db) . await ;
449
458
@@ -462,7 +471,7 @@ mod tests {
462
471
463
472
db_insert_requests ( & * db, & [ release] ) . await ;
464
473
465
- enqueue_next_job ( & mut * db) . await ?;
474
+ enqueue_next_job ( & mut * db, true ) . await ?;
466
475
467
476
let in_progress = get_in_progress ( & * db) . await ;
468
477
@@ -486,7 +495,7 @@ mod tests {
486
495
let m2 = create_master ( "new" , "y" , 4 , "days1" ) ;
487
496
488
497
db_insert_requests ( & * db, & [ c1, c2, m1, m2] ) . await ;
489
- enqueue_next_job ( & mut * db) . await ?;
498
+ enqueue_next_job ( & mut * db, true ) . await ?;
490
499
491
500
let in_progress = get_in_progress ( & * db) . await ;
492
501
@@ -506,7 +515,7 @@ mod tests {
506
515
let orphan = create_master ( "orphan" , "gone" , 42 , "days1" ) ;
507
516
508
517
db_insert_requests ( & * db, & [ orphan] ) . await ;
509
- enqueue_next_job ( & mut * db) . await ?;
518
+ enqueue_next_job ( & mut * db, true ) . await ?;
510
519
511
520
let in_progress = get_in_progress ( & * db) . await ;
512
521
assert_eq ! ( in_progress. unwrap( ) . tag( ) , "orphan" ) ;
@@ -559,7 +568,7 @@ mod tests {
559
568
] ;
560
569
561
570
db_insert_requests ( & * db, & requests) . await ;
562
- enqueue_next_job ( & mut * db) . await ?;
571
+ enqueue_next_job ( & mut * db, true ) . await ?;
563
572
564
573
// The oldest release ("v0.8.0") outranks everything else
565
574
let in_progress = get_in_progress ( & * db) . await ;
@@ -606,7 +615,7 @@ mod tests {
606
615
] ;
607
616
608
617
db_insert_requests ( & * db, & requests) . await ;
609
- enqueue_next_job ( & mut * db) . await ?;
618
+ enqueue_next_job ( & mut * db, true ) . await ?;
610
619
611
620
// The oldest release ("v0.8.0") outranks everything else
612
621
let in_progress = get_in_progress ( & * db) . await ;
0 commit comments