@@ -9,8 +9,8 @@ use collector::benchmark_set::benchmark_set_count;
99use database:: pool:: { JobEnqueueResult , Transaction } ;
1010use database:: {
1111 BenchmarkJobKind , BenchmarkRequest , BenchmarkRequestIndex , BenchmarkRequestStatus ,
12- BenchmarkRequestType , CodegenBackend , Date , PendingBenchmarkRequests , Profile , QueuedCommit ,
13- Target ,
12+ BenchmarkRequestType , CodegenBackend , Connection , Date , PendingBenchmarkRequests , Profile ,
13+ QueuedCommit , Target ,
1414} ;
1515use parking_lot:: RwLock ;
1616use std:: sync:: Arc ;
@@ -370,12 +370,12 @@ pub async fn enqueue_benchmark_request(
370370/// Returns benchmark requests that were completed.
371371async fn process_benchmark_requests (
372372 conn : & mut dyn database:: pool:: Connection ,
373- ) -> anyhow:: Result < Vec < BenchmarkRequest > > {
373+ completed_benchmarks : & mut Vec < BenchmarkRequest > ,
374+ ) -> anyhow:: Result < ( ) > {
374375 let queue = build_queue ( conn) . await ?;
375376
376377 log:: debug!( "Current queue: {queue:?}" ) ;
377378
378- let mut completed = vec ! [ ] ;
379379 for request in queue {
380380 match request. status ( ) {
381381 BenchmarkRequestStatus :: InProgress => {
@@ -386,7 +386,7 @@ async fn process_benchmark_requests(
386386 . context ( "cannot mark benchmark request as completed" ) ?
387387 {
388388 log:: info!( "Request {tag} marked as completed" ) ;
389- completed . push ( request) ;
389+ completed_benchmarks . push ( request) ;
390390 continue ;
391391 }
392392 break ;
@@ -403,7 +403,7 @@ async fn process_benchmark_requests(
403403 }
404404 }
405405 }
406- Ok ( completed )
406+ Ok ( ( ) )
407407}
408408
409409/// Creates new benchmark requests, enqueues jobs for ready benchmark requests and
@@ -432,73 +432,108 @@ async fn perform_queue_tick(ctxt: &SiteCtxt) -> anyhow::Result<()> {
432432 log:: error!( "Could not insert release benchmark requests into the database: {error:?}" ) ;
433433 }
434434 }
435+
436+ let mut completed_benchmarks = vec ! [ ] ;
435437 // Enqueue waiting requests and try to complete in-progress ones
436- let completed_reqs = process_benchmark_requests ( & mut * conn)
438+ let mut result = process_benchmark_requests ( & mut * conn, & mut completed_benchmarks )
437439 . await
438- . context ( "Failed to process benchmark requests" ) ?;
440+ . context ( "Failed to process benchmark requests" ) ;
441+
442+ // Send a comment to GitHub for completed requests and reload the DB index,
443+ // regardless whether there was an error when processing the requests or not.
444+ if !completed_benchmarks. is_empty ( ) {
445+ result = combine_result (
446+ result,
447+ handle_completed_requests ( ctxt, & mut * conn, completed_benchmarks)
448+ . await
449+ . context ( "Failed to send comparison comment(s)" ) ,
450+ ) ;
451+ }
439452
440453 // If some change happened, reload the benchmark request index
441454 if requests_inserted {
442- ctxt. known_benchmark_requests . store ( Arc :: new (
443- conn. load_benchmark_request_index ( )
444- . await
445- . context ( "Failed to load benchmark request index" ) ?,
446- ) ) ;
455+ match conn
456+ . load_benchmark_request_index ( )
457+ . await
458+ . context ( "Failed to load benchmark request index" )
459+ {
460+ Ok ( index) => {
461+ ctxt. known_benchmark_requests . store ( Arc :: new ( index) ) ;
462+ }
463+ Err ( error) => {
464+ result = combine_result ( result, Err ( error) ) ;
465+ }
466+ } ;
467+ }
468+
469+ // Propagate the error
470+ result
471+ }
472+
473+ fn combine_result < T > ( a : anyhow:: Result < T > , b : anyhow:: Result < T > ) -> anyhow:: Result < T > {
474+ match ( a, b) {
475+ ( Ok ( v) , Ok ( _) ) => Ok ( v) ,
476+ ( Err ( e) , Ok ( _) ) | ( Ok ( _) , Err ( e) ) => Err ( e) ,
477+ ( Err ( e1) , Err ( e2) ) => Err ( anyhow:: anyhow!( "{e2:?}\n \n Preceded by: {e1:?}" ) ) ,
447478 }
479+ }
448480
449- // Send a comment to GitHub for completed requests and reload the DB index
450- if !completed_reqs. is_empty ( ) {
451- let index = database:: Index :: load ( & mut * conn) . await ;
452- log:: info!( "index has {} commits" , index. commits( ) . len( ) ) ;
453- ctxt. index . store ( Arc :: new ( index) ) ;
454-
455- // Refresh the landing page
456- ctxt. landing_page . store ( Arc :: new ( None ) ) ;
457-
458- // Send comments to GitHub
459- for request in completed_reqs {
460- let ( is_master, pr, sha, parent_sha) = match request. commit_type ( ) {
461- BenchmarkRequestType :: Try {
462- pr,
463- parent_sha,
464- sha,
465- } => (
466- false ,
467- * pr,
468- sha. clone ( ) . expect ( "Completed try commit without a SHA" ) ,
469- parent_sha
470- . clone ( )
471- . expect ( "Completed try commit without a parent SHA" ) ,
472- ) ,
473- BenchmarkRequestType :: Master {
474- pr,
475- sha,
476- parent_sha,
477- } => ( true , * pr, sha. clone ( ) , parent_sha. clone ( ) ) ,
478- BenchmarkRequestType :: Release { .. } => continue ,
479- } ;
480- let commit = QueuedCommit {
481+ /// Reload the main index and send GitHub comments.
482+ async fn handle_completed_requests (
483+ ctxt : & SiteCtxt ,
484+ conn : & mut dyn Connection ,
485+ completed_benchmarks : Vec < BenchmarkRequest > ,
486+ ) -> anyhow:: Result < ( ) > {
487+ // Reload the index, so that it has the new results
488+ let index = database:: Index :: load ( conn) . await ;
489+ log:: info!( "Index has {} commits" , index. commits( ) . len( ) ) ;
490+ ctxt. index . store ( Arc :: new ( index) ) ;
491+
492+ // Refresh the landing page
493+ ctxt. landing_page . store ( Arc :: new ( None ) ) ;
494+
495+ // Send comments to GitHub
496+ for request in completed_benchmarks {
497+ let ( is_master, pr, sha, parent_sha) = match request. commit_type ( ) {
498+ BenchmarkRequestType :: Try {
499+ pr,
500+ parent_sha,
501+ sha,
502+ } => (
503+ false ,
504+ * pr,
505+ sha. clone ( ) . expect ( "Completed try commit without a SHA" ) ,
506+ parent_sha
507+ . clone ( )
508+ . expect ( "Completed try commit without a parent SHA" ) ,
509+ ) ,
510+ BenchmarkRequestType :: Master {
481511 pr,
482512 sha,
483513 parent_sha,
484- include : None ,
485- exclude : None ,
486- runs : None ,
487- commit_date : request. commit_date ( ) . map ( Date ) ,
488- backends : Some (
489- request
490- . backends ( ) ?
491- . into_iter ( )
492- . map ( |b| b. as_str ( ) )
493- . collect :: < Vec < _ > > ( )
494- . join ( "," ) ,
495- ) ,
496- } ;
497- log:: debug!( "Posting comparison comment to {pr}" ) ;
498- post_comparison_comment ( ctxt, commit, is_master) . await ?;
499- }
514+ } => ( true , * pr, sha. clone ( ) , parent_sha. clone ( ) ) ,
515+ BenchmarkRequestType :: Release { .. } => continue ,
516+ } ;
517+ let commit = QueuedCommit {
518+ pr,
519+ sha,
520+ parent_sha,
521+ include : None ,
522+ exclude : None ,
523+ runs : None ,
524+ commit_date : request. commit_date ( ) . map ( Date ) ,
525+ backends : Some (
526+ request
527+ . backends ( ) ?
528+ . into_iter ( )
529+ . map ( |b| b. as_str ( ) )
530+ . collect :: < Vec < _ > > ( )
531+ . join ( "," ) ,
532+ ) ,
533+ } ;
534+ log:: debug!( "Posting comparison comment to {pr}" ) ;
535+ post_comparison_comment ( ctxt, commit, is_master) . await ?;
500536 }
501-
502537 Ok ( ( ) )
503538}
504539
@@ -743,7 +778,7 @@ mod tests {
743778 ctx. complete_request ( "bar" ) . await ;
744779 ctx. insert_master_request ( "foo" , "bar" , 1 ) . await ;
745780
746- process_benchmark_requests ( ctx. db_mut ( ) ) . await ?;
781+ process_benchmark_requests ( ctx. db_mut ( ) , & mut vec ! [ ] ) . await ?;
747782 let jobs = ctx
748783 . db ( )
749784 . get_jobs_of_in_progress_benchmark_requests ( )
0 commit comments