@@ -27,7 +27,7 @@ async fn create_benchmark_request_master_commits(
2727)  -> anyhow:: Result < ( ) >  { 
2828    let  master_commits = & ctxt. get_master_commits ( ) . commits ; 
2929    // TODO; delete at some point in the future 
30-     let  cutoff:  chrono:: DateTime < Utc >  = chrono:: DateTime :: from_str ( "2025-06-01T00 :00:00.000Z" ) ?; 
30+     let  cutoff:  chrono:: DateTime < Utc >  = chrono:: DateTime :: from_str ( "2025-07-24T00 :00:00.000Z" ) ?; 
3131
3232    for  master_commit in  master_commits { 
3333        // We don't want to add masses of obsolete data 
@@ -39,6 +39,7 @@ async fn create_benchmark_request_master_commits(
3939                pr, 
4040                master_commit. time , 
4141            ) ; 
42+             log:: info!( "Inserting master benchmark request {benchmark:?}" ) ; 
4243            if  let  Err ( error)  = conn. insert_benchmark_request ( & benchmark) . await  { 
4344                log:: error!( "Failed to insert master benchmark request: {error:?}" ) ; 
4445            } 
@@ -70,6 +71,7 @@ async fn create_benchmark_request_releases(
7071    for  ( name,  date_time)  in  releases { 
7172        if  date_time >= cutoff && !index. contains_tag ( & name)  { 
7273            let  release_request = BenchmarkRequest :: create_release ( & name,  date_time) ; 
74+             log:: info!( "Inserting release benchmark request {release_request:?}" ) ; 
7375            if  let  Err ( error)  = conn. insert_benchmark_request ( & release_request) . await  { 
7476                log:: error!( "Failed to insert release benchmark request: {error}" ) ; 
7577            } 
@@ -104,9 +106,9 @@ fn sort_benchmark_requests(index: &BenchmarkRequestIndex, request_queue: &mut [B
104106        // just won't have a parent result available. 
105107        if  level_len == 0  { 
106108            if  cfg ! ( test)  { 
107-                 panic ! ( "No commit is ready for benchmarking" ) ; 
109+                 panic ! ( "No master/try  commit is ready for benchmarking" ) ; 
108110            }  else  { 
109-                 log:: warn!( "No commit is ready for benchmarking" ) ; 
111+                 log:: warn!( "No master/try  commit is ready for benchmarking" ) ; 
110112                return ; 
111113            } 
112114        } 
@@ -175,20 +177,23 @@ pub async fn build_queue(
175177    Ok ( queue) 
176178} 
177179
178- /// From a benchmark_request create all the required jobs 
179- pub  async  fn  create_benchmark_jobs ( 
180+ /// Create all necessary jobs for the given benchmark request 
181+ /// and mark it as being in progress. 
182+ /// This is performed atomically, in a transaction. 
183+ pub  async  fn  enqueue_benchmark_request ( 
180184    conn :  & mut  dyn  database:: pool:: Connection , 
181185    benchmark_request :  & BenchmarkRequest , 
182186)  -> anyhow:: Result < ( ) >  { 
183187    let  mut  tx = conn. transaction ( ) . await ; 
184-     anyhow:: ensure!( 
185-         benchmark_request. tag( ) . is_some( ) , 
186-         "Benchmark request has no tag" 
187-     ) ; 
188+ 
189+     let  Some ( request_tag)  = benchmark_request. tag ( )  else  { 
190+         panic ! ( "Benchmark request {benchmark_request:?} has no tag" ) ; 
191+     } ; 
192+ 
193+     log:: info!( "Enqueuing jobs for request {benchmark_request:?}" ) ; 
188194
189195    let  backends = benchmark_request. backends ( ) ?; 
190196    let  profiles = benchmark_request. profiles ( ) ?; 
191-     let  request_tag = benchmark_request. tag ( ) . unwrap ( ) ; 
192197
193198    // Target x benchmark_set x backend x profile -> BenchmarkJob 
194199    for  target in  Target :: all ( )  { 
@@ -206,7 +211,7 @@ pub async fn create_benchmark_jobs(
206211                            benchmark_set as  u32 , 
207212                        ) 
208213                        . await ?; 
209-                     // If there is a parent, we create a job for it to . The 
214+                     // If there is a parent, we create a job for it too . The 
210215                    // database will ignore it if there is already a job there. 
211216                    // If the parent job has been deleted from the database 
212217                    // but was already benchmarked then the collector will ignore 
@@ -234,16 +239,29 @@ pub async fn create_benchmark_jobs(
234239    Ok ( ( ) ) 
235240} 
236241
237- /// Enqueue the job into the job_queue 
238- async  fn  enqueue_next_job ( 
242+ /// Try to find a benchmark request that should be enqueue next, and if such request is found, 
243+ /// enqueue it. 
244+ async  fn  try_enqueue_next_benchmark_request ( 
239245    conn :  & mut  dyn  database:: pool:: Connection , 
240246    index :  & mut  BenchmarkRequestIndex , 
241247)  -> anyhow:: Result < ( ) >  { 
242248    let  queue = build_queue ( conn,  index) . await ?; 
249+ 
250+     #[ allow( clippy:: never_loop) ]  
243251    for  request in  queue { 
244-         if  request. status ( )  != BenchmarkRequestStatus :: InProgress  { 
245-             create_benchmark_jobs ( conn,  & request) . await ?; 
246-             break ; 
252+         match  request. status ( )  { 
253+             BenchmarkRequestStatus :: ArtifactsReady  => { 
254+                 enqueue_benchmark_request ( conn,  & request) . await ?; 
255+                 break ; 
256+             } 
257+             BenchmarkRequestStatus :: InProgress  => { 
258+                 // TODO: Try to mark as completed 
259+                 break ; 
260+             } 
261+             BenchmarkRequestStatus :: WaitingForArtifacts 
262+             | BenchmarkRequestStatus :: Completed  {  .. }  => { 
263+                 unreachable ! ( "Unexpected request {request:?} found in request queue" ) ; 
264+             } 
247265        } 
248266    } 
249267    Ok ( ( ) ) 
@@ -257,7 +275,7 @@ async fn cron_enqueue_jobs(site_ctxt: &Arc<SiteCtxt>) -> anyhow::Result<()> {
257275    create_benchmark_request_master_commits ( site_ctxt,  & * conn,  & index) . await ?; 
258276    // Put the releases into the `benchmark_requests` queue 
259277    create_benchmark_request_releases ( & * conn,  & index) . await ?; 
260-     enqueue_next_job ( & mut  * conn,  & mut  index) . await ?; 
278+     try_enqueue_next_benchmark_request ( & mut  * conn,  & mut  index) . await ?; 
261279    Ok ( ( ) ) 
262280} 
263281
@@ -274,8 +292,8 @@ pub async fn cron_main(site_ctxt: Arc<RwLock<Option<Arc<SiteCtxt>>>>, seconds: u
274292            guard. as_ref ( ) . cloned ( ) 
275293        }  { 
276294            match  cron_enqueue_jobs ( & ctxt_clone) . await  { 
277-                 Ok ( _)  => log:: info!( "Cron job executed at: {:?}"  ,  std :: time :: SystemTime :: now ( ) ) , 
278-                 Err ( e)  => log:: error!( "Cron job failed to execute {}"  ,  e ) , 
295+                 Ok ( _)  => log:: info!( "Cron job finished"  ) , 
296+                 Err ( e)  => log:: error!( "Cron job failed to execute: {e:?}"  ) , 
279297            } 
280298        } 
281299    } 
0 commit comments