@@ -252,7 +252,10 @@ pub async fn build_queue(
252252}
253253
254254/// 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 < ( ) > {
256259 // We draw back all completed requests
257260 let completed: HashSet < String > = conn
258261 . get_benchmark_requests_by_status ( & [ BenchmarkRequestStatus :: Completed ] )
@@ -265,26 +268,32 @@ async fn enqueue_next_job(conn: &mut dyn database::pool::Connection) -> anyhow::
265268
266269 if let Some ( request) = queue. into_iter ( ) . next ( ) {
267270 if request. status != BenchmarkRequestStatus :: InProgress {
268- log:: info!( "{:?} would have been marked as InProgress" , request) ;
269271 // TODO:
270- // - Uncomment this code
272+ // - Remove this if condition
271273 // - 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+ }
274280 }
275281 }
276282
277283 Ok ( ( ) )
278284}
279285
280286/// 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 < ( ) > {
282291 let mut conn = site_ctxt. conn ( ) . await ;
283292 // Put the master commits into the `benchmark_requests` queue
284293 create_benchmark_request_master_commits ( site_ctxt, & * conn) . await ?;
285294 // Put the releases into the `benchmark_requests` queue
286295 create_benchmark_request_releases ( & * conn) . await ?;
287- enqueue_next_job ( & mut * conn) . await ?;
296+ enqueue_next_job ( & mut * conn, should_add_to_db ) . await ?;
288297 Ok ( ( ) )
289298}
290299
@@ -300,7 +309,7 @@ pub async fn cron_main(site_ctxt: Arc<RwLock<Option<Arc<SiteCtxt>>>>, seconds: u
300309 let guard = ctxt. read ( ) ;
301310 guard. as_ref ( ) . cloned ( )
302311 } {
303- match cron_enqueue_jobs ( & ctxt_clone) . await {
312+ match cron_enqueue_jobs ( & ctxt_clone, false ) . await {
304313 Ok ( _) => log:: info!( "Cron job executed at: {:?}" , std:: time:: SystemTime :: now( ) ) ,
305314 Err ( e) => log:: error!( "Cron job failed to execute {}" , e) ,
306315 }
@@ -422,7 +431,7 @@ mod tests {
422431 run_postgres_test ( |ctx| async {
423432 let mut db = ctx. db_client ( ) . connection ( ) . await ;
424433
425- enqueue_next_job ( & mut * db) . await ?;
434+ enqueue_next_job ( & mut * db, true ) . await ?;
426435
427436 let in_progress = get_in_progress ( & * db) . await ;
428437
@@ -443,7 +452,7 @@ mod tests {
443452
444453 db_insert_requests ( & * db, & [ parent, child] ) . await ;
445454
446- enqueue_next_job ( & mut * db) . await ?;
455+ enqueue_next_job ( & mut * db, true ) . await ?;
447456
448457 let in_progress = get_in_progress ( & * db) . await ;
449458
@@ -462,7 +471,7 @@ mod tests {
462471
463472 db_insert_requests ( & * db, & [ release] ) . await ;
464473
465- enqueue_next_job ( & mut * db) . await ?;
474+ enqueue_next_job ( & mut * db, true ) . await ?;
466475
467476 let in_progress = get_in_progress ( & * db) . await ;
468477
@@ -486,7 +495,7 @@ mod tests {
486495 let m2 = create_master ( "new" , "y" , 4 , "days1" ) ;
487496
488497 db_insert_requests ( & * db, & [ c1, c2, m1, m2] ) . await ;
489- enqueue_next_job ( & mut * db) . await ?;
498+ enqueue_next_job ( & mut * db, true ) . await ?;
490499
491500 let in_progress = get_in_progress ( & * db) . await ;
492501
@@ -506,7 +515,7 @@ mod tests {
506515 let orphan = create_master ( "orphan" , "gone" , 42 , "days1" ) ;
507516
508517 db_insert_requests ( & * db, & [ orphan] ) . await ;
509- enqueue_next_job ( & mut * db) . await ?;
518+ enqueue_next_job ( & mut * db, true ) . await ?;
510519
511520 let in_progress = get_in_progress ( & * db) . await ;
512521 assert_eq ! ( in_progress. unwrap( ) . tag( ) , "orphan" ) ;
@@ -559,7 +568,7 @@ mod tests {
559568 ] ;
560569
561570 db_insert_requests ( & * db, & requests) . await ;
562- enqueue_next_job ( & mut * db) . await ?;
571+ enqueue_next_job ( & mut * db, true ) . await ?;
563572
564573 // The oldest release ("v0.8.0") outranks everything else
565574 let in_progress = get_in_progress ( & * db) . await ;
@@ -606,7 +615,7 @@ mod tests {
606615 ] ;
607616
608617 db_insert_requests ( & * db, & requests) . await ;
609- enqueue_next_job ( & mut * db) . await ?;
618+ enqueue_next_job ( & mut * db, true ) . await ?;
610619
611620 // The oldest release ("v0.8.0") outranks everything else
612621 let in_progress = get_in_progress ( & * db) . await ;
0 commit comments