@@ -676,17 +676,17 @@ pub async fn queue_rebuilds(
676676 config : & Config ,
677677 build_queue : & AsyncBuildQueue ,
678678) -> Result < ( ) > {
679- let already_queued_rebuilds = sqlx :: query_scalar! (
680- r#"SELECT COUNT(*) as "count!" FROM queue WHERE priority >= $1"# ,
681- REBUILD_PRIORITY
682- )
683- . fetch_one ( & mut * conn )
684- . await ? ;
679+ let already_queued_rebuilds: usize = build_queue
680+ . pending_count_by_priority ( )
681+ . await ?
682+ . iter ( )
683+ . filter_map ( | ( priority , count ) | ( * priority >= REBUILD_PRIORITY ) . then_some ( count ) )
684+ . sum ( ) ;
685685
686686 let rebuilds_to_queue = config
687687 . max_queued_rebuilds
688688 . expect ( "config.max_queued_rebuilds not set" ) as i64
689- - already_queued_rebuilds;
689+ - already_queued_rebuilds as i64 ;
690690
691691 if rebuilds_to_queue <= 0 {
692692 info ! ( "not queueing rebuilds; queue limit reached" ) ;
@@ -806,6 +806,47 @@ mod tests {
806806 } )
807807 }
808808
809+ #[ test]
810+ fn test_still_rebuild_when_full_with_failed ( ) {
811+ crate :: test:: async_wrapper ( |env| async move {
812+ env. override_config ( |config| {
813+ config. max_queued_rebuilds = Some ( 1 ) ;
814+ config. rebuild_up_to_date = Some ( NaiveDate :: from_ymd_opt ( 2024 , 1 , 1 ) . unwrap ( ) ) ;
815+ } ) ;
816+
817+ let build_queue = env. async_build_queue ( ) . await ;
818+ build_queue
819+ . add_crate ( "foo1" , "0.1.0" , REBUILD_PRIORITY , None )
820+ . await ?;
821+ build_queue
822+ . add_crate ( "foo2" , "0.1.0" , REBUILD_PRIORITY , None )
823+ . await ?;
824+
825+ let mut conn = env. async_db ( ) . await . async_conn ( ) . await ;
826+ sqlx:: query!( "UPDATE queue SET attempt = 99" )
827+ . execute ( & mut * conn)
828+ . await ?;
829+
830+ assert_eq ! ( build_queue. queued_crates( ) . await ?. len( ) , 0 ) ;
831+
832+ env. async_fake_release ( )
833+ . await
834+ . name ( "foo" )
835+ . version ( "0.1.0" )
836+ . builds ( vec ! [ FakeBuild :: default ( )
837+ . rustc_version( "rustc 1.84.0-nightly (e7c0d2750 2020-10-15)" ) ] )
838+ . create_async ( )
839+ . await ?;
840+
841+ let build_queue = env. async_build_queue ( ) . await ;
842+ queue_rebuilds ( & mut conn, & env. config ( ) , & build_queue) . await ?;
843+
844+ assert_eq ! ( build_queue. queued_crates( ) . await ?. len( ) , 1 ) ;
845+
846+ Ok ( ( ) )
847+ } )
848+ }
849+
809850 #[ test]
810851 fn test_dont_rebuild_when_full ( ) {
811852 crate :: test:: async_wrapper ( |env| async move {
0 commit comments