diff --git a/.sqlx/query-007c5f49470ce1bc503f82003377d80cc4be3282ca1b9c37c1b2e8c28dff53d0.json b/.sqlx/query-007c5f49470ce1bc503f82003377d80cc4be3282ca1b9c37c1b2e8c28dff53d0.json deleted file mode 100644 index 856d46f21..000000000 --- a/.sqlx/query-007c5f49470ce1bc503f82003377d80cc4be3282ca1b9c37c1b2e8c28dff53d0.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "db_name": "PostgreSQL", - "query": "SELECT COUNT(*) as \"count!\" FROM queue WHERE priority >= $1", - "describe": { - "columns": [ - { - "ordinal": 0, - "name": "count!", - "type_info": "Int8" - } - ], - "parameters": { - "Left": [ - "Int4" - ] - }, - "nullable": [ - null - ] - }, - "hash": "007c5f49470ce1bc503f82003377d80cc4be3282ca1b9c37c1b2e8c28dff53d0" -} diff --git a/.sqlx/query-7fad5d5fdee0a32f79f34f22bee0e8cfc48521abe29f2570be40e76d9b5bab16.json b/.sqlx/query-7fad5d5fdee0a32f79f34f22bee0e8cfc48521abe29f2570be40e76d9b5bab16.json new file mode 100644 index 000000000..2855df519 --- /dev/null +++ b/.sqlx/query-7fad5d5fdee0a32f79f34f22bee0e8cfc48521abe29f2570be40e76d9b5bab16.json @@ -0,0 +1,12 @@ +{ + "db_name": "PostgreSQL", + "query": "UPDATE queue SET attempt = 99", + "describe": { + "columns": [], + "parameters": { + "Left": [] + }, + "nullable": [] + }, + "hash": "7fad5d5fdee0a32f79f34f22bee0e8cfc48521abe29f2570be40e76d9b5bab16" +} diff --git a/src/build_queue.rs b/src/build_queue.rs index 4d2319a4e..a40acc86c 100644 --- a/src/build_queue.rs +++ b/src/build_queue.rs @@ -676,17 +676,17 @@ pub async fn queue_rebuilds( config: &Config, build_queue: &AsyncBuildQueue, ) -> Result<()> { - let already_queued_rebuilds = sqlx::query_scalar!( - r#"SELECT COUNT(*) as "count!" FROM queue WHERE priority >= $1"#, - REBUILD_PRIORITY - ) - .fetch_one(&mut *conn) - .await?; + let already_queued_rebuilds: usize = build_queue + .pending_count_by_priority() + .await? + .iter() + .filter_map(|(priority, count)| (*priority >= REBUILD_PRIORITY).then_some(count)) + .sum(); let rebuilds_to_queue = config .max_queued_rebuilds .expect("config.max_queued_rebuilds not set") as i64 - - already_queued_rebuilds; + - already_queued_rebuilds as i64; if rebuilds_to_queue <= 0 { info!("not queueing rebuilds; queue limit reached"); @@ -806,6 +806,47 @@ mod tests { }) } + #[test] + fn test_still_rebuild_when_full_with_failed() { + crate::test::async_wrapper(|env| async move { + env.override_config(|config| { + config.max_queued_rebuilds = Some(1); + config.rebuild_up_to_date = Some(NaiveDate::from_ymd_opt(2024, 1, 1).unwrap()); + }); + + let build_queue = env.async_build_queue().await; + build_queue + .add_crate("foo1", "0.1.0", REBUILD_PRIORITY, None) + .await?; + build_queue + .add_crate("foo2", "0.1.0", REBUILD_PRIORITY, None) + .await?; + + let mut conn = env.async_db().await.async_conn().await; + sqlx::query!("UPDATE queue SET attempt = 99") + .execute(&mut *conn) + .await?; + + assert_eq!(build_queue.queued_crates().await?.len(), 0); + + env.async_fake_release() + .await + .name("foo") + .version("0.1.0") + .builds(vec![FakeBuild::default() + .rustc_version("rustc 1.84.0-nightly (e7c0d2750 2020-10-15)")]) + .create_async() + .await?; + + let build_queue = env.async_build_queue().await; + queue_rebuilds(&mut conn, &env.config(), &build_queue).await?; + + assert_eq!(build_queue.queued_crates().await?.len(), 1); + + Ok(()) + }) + } + #[test] fn test_dont_rebuild_when_full() { crate::test::async_wrapper(|env| async move {