fc-common: add get_cancelled_among query for cancel-checker polling

Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: Iabc5fc932c8d7f1d19a80a27965524136a6a6964
This commit is contained in:
raf 2026-02-16 23:27:03 +03:00
commit d401177902
Signed by: NotAShelf
GPG key ID: 29D95B64378DB4BF

View file

@ -229,6 +229,26 @@ pub async fn count_filtered(
Ok(row.0)
}
/// Return the subset of the given build IDs whose status is 'cancelled'.
/// Used by the cancel-checker loop to detect builds cancelled while running.
pub async fn get_cancelled_among(
pool: &PgPool,
build_ids: &[Uuid],
) -> Result<Vec<Uuid>> {
if build_ids.is_empty() {
return Ok(Vec::new());
}
let rows: Vec<(Uuid,)> = sqlx::query_as(
"SELECT id FROM builds WHERE id = ANY($1) AND status = 'cancelled'",
)
.bind(build_ids)
.fetch_all(pool)
.await
.map_err(CiError::Database)?;
Ok(rows.into_iter().map(|(id,)| id).collect())
}
pub async fn cancel(pool: &PgPool, id: Uuid) -> Result<Build> {
sqlx::query_as::<_, Build>(
"UPDATE builds SET status = 'cancelled', completed_at = NOW() WHERE id = \