crates/common: update repos for weighted scheduling and jobset inputs
Signed-off-by: NotAShelf <raf@notashelf.dev> Change-Id: I0fe2ceb20dc6692f3315185765ea80756a6a6964
This commit is contained in:
parent
4c5a99d554
commit
2378ff6661
4 changed files with 77 additions and 7 deletions
|
|
@ -60,7 +60,12 @@ pub async fn list_for_evaluation(pool: &PgPool, evaluation_id: Uuid) -> Result<V
|
|||
|
||||
pub async fn list_pending(pool: &PgPool, limit: i64) -> Result<Vec<Build>> {
|
||||
sqlx::query_as::<_, Build>(
|
||||
"SELECT * FROM builds WHERE status = 'pending' ORDER BY priority DESC, created_at ASC LIMIT $1",
|
||||
"SELECT b.* FROM builds b \
|
||||
JOIN evaluations e ON b.evaluation_id = e.id \
|
||||
JOIN jobsets j ON e.jobset_id = j.id \
|
||||
WHERE b.status = 'pending' \
|
||||
ORDER BY b.priority DESC, j.scheduling_shares DESC, b.created_at ASC \
|
||||
LIMIT $1",
|
||||
)
|
||||
.bind(limit)
|
||||
.fetch_all(pool)
|
||||
|
|
@ -245,6 +250,25 @@ pub async fn cancel_cascade(pool: &PgPool, id: Uuid) -> Result<Vec<Build>> {
|
|||
Ok(cancelled)
|
||||
}
|
||||
|
||||
/// Restart a build by resetting it to pending state.
|
||||
/// Only works for failed, completed, or cancelled builds.
|
||||
pub async fn restart(pool: &PgPool, id: Uuid) -> Result<Build> {
|
||||
sqlx::query_as::<_, Build>(
|
||||
"UPDATE builds SET status = 'pending', started_at = NULL, completed_at = NULL, \
|
||||
log_path = NULL, build_output_path = NULL, error_message = NULL, \
|
||||
retry_count = retry_count + 1 \
|
||||
WHERE id = $1 AND status IN ('failed', 'completed', 'cancelled') RETURNING *",
|
||||
)
|
||||
.bind(id)
|
||||
.fetch_optional(pool)
|
||||
.await?
|
||||
.ok_or_else(|| {
|
||||
CiError::NotFound(format!(
|
||||
"Build {id} not found or not in a restartable state"
|
||||
))
|
||||
})
|
||||
}
|
||||
|
||||
/// Mark a build's outputs as signed.
|
||||
pub async fn mark_signed(pool: &PgPool, id: Uuid) -> Result<()> {
|
||||
sqlx::query("UPDATE builds SET signed = true WHERE id = $1")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue