From 94faed5bdffc2dc3314a71c95322a8626f02b4f6 Mon Sep 17 00:00:00 2001 From: dieriba Date: Thu, 13 Nov 2025 19:02:48 +0100 Subject: [PATCH] jobs update --- backend/windmill-api/src/jobs.rs | 199 ------------------------------- 1 file changed, 199 deletions(-) diff --git a/backend/windmill-api/src/jobs.rs b/backend/windmill-api/src/jobs.rs index 12c30a5517..24789f5f00 100644 --- a/backend/windmill-api/src/jobs.rs +++ b/backend/windmill-api/src/jobs.rs @@ -344,22 +344,6 @@ pub fn workspaced_service() -> Router { "/send_email_with_instance_smtp", post(send_email_with_instance_smtp), ) - .route( - "/resume_suspended/:job_id/:resume_id", - post(resume_suspended_job_auth), - ) - .route( - "/cancel_suspended/:job_id/:resume_id", - post(cancel_suspended_job_auth), - ) - .route( - "/resume_suspended_batch/:suspend_number", - post(resume_suspended_batch_auth), - ) - .route( - "/cancel_suspended_batch/:suspend_number", - post(cancel_suspended_batch_auth), - ) } pub fn workspace_unauthed_service() -> Router { @@ -8390,186 +8374,3 @@ async fn delete_completed_job<'a>( ) .await; } - -pub async fn resume_suspended_job_auth( - authed: ApiAuthed, - Extension(db): Extension, - Path((w_id, job_id, suspend_number)): Path<(String, Uuid, i32)>, -) -> error::Result { - let mut tx: Transaction<'_, Postgres> = db.begin().await?; - - let rows_affected = sqlx::query!( - "UPDATE v2_job_queue SET suspend = NULL WHERE id = $1 AND workspace_id = $2 AND suspend = $3", - job_id, - w_id, - suspend_number - ) - .execute(&mut *tx) - .await? - .rows_affected(); - - if rows_affected == 0 { - return Err( - anyhow::anyhow!("No suspended job found with this job_id and suspend_number").into(), - ); - } - - audit_log( - &mut *tx, - &authed, - "jobs.suspend_resume", - ActionKind::Update, - &w_id, - Some( - &serde_json::json!({ - "approved": true, - "job_id": job_id, - "suspend_number": suspend_number, - "details": format!("Resumed by {}", &authed.username) - }) - .to_string(), - ), - None, - ) - .await?; - tx.commit().await?; - Ok(StatusCode::OK) -} - -pub async fn cancel_suspended_job_auth( - authed: ApiAuthed, - Extension(db): Extension, - Path((w_id, job_id, suspend_number)): Path<(String, Uuid, i32)>, -) -> error::Result { - let mut tx: Transaction<'_, Postgres> = db.begin().await?; - - audit_log( - &mut *tx, - &authed, - "jobs.suspend_cancel", - ActionKind::Delete, - &w_id, - Some( - &serde_json::json!({ - "job_id": job_id, - "suspend_number": suspend_number, - "details": format!("Cancelled and deleted by {}", &authed.username) - }) - .to_string(), - ), - None, - ) - .await?; - tx.commit().await?; - Ok(StatusCode::OK) -} -pub async fn resume_suspended_batch_auth( - authed: ApiAuthed, - Extension(db): Extension, - Path((w_id, suspend_number)): Path<(String, i32)>, -) -> error::Result { - let mut tx: Transaction<'_, Postgres> = db.begin().await?; - - let rows_affected = sqlx::query!( - "UPDATE v2_job_queue SET suspend = NULL WHERE workspace_id = $1 AND suspend = $2", - w_id, - suspend_number - ) - .execute(&mut *tx) - .await? - .rows_affected(); - - if rows_affected == 0 { - return Err(anyhow::anyhow!("No suspended jobs found with this suspend number").into()); - } - - audit_log( - &mut *tx, - &authed, - "jobs.suspend_resume_batch", - ActionKind::Update, - &w_id, - Some( - &serde_json::json!({ - "approved": true, - "suspend_number": suspend_number, - "job_count": rows_affected, - "details": format!("Batch resumed {} jobs by {}", rows_affected, &authed.username) - }) - .to_string(), - ), - None, - ) - .await?; - tx.commit().await?; - Ok(StatusCode::OK) -} - -pub async fn cancel_suspended_batch_auth( - authed: ApiAuthed, - Extension(db): Extension, - Path((w_id, suspend_number)): Path<(String, i32)>, -) -> error::Result { - let mut tx: Transaction<'_, Postgres> = db.begin().await?; - - let suspended_jobs = sqlx::query!( - "SELECT id FROM v2_job_queue WHERE workspace_id = $1 AND suspend = $2", - w_id, - suspend_number - ) - .fetch_all(&mut *tx) - .await?; - - if suspended_jobs.is_empty() { - return Err(anyhow::anyhow!("No suspended jobs found with this suspend number").into()); - } - - let job_count = suspended_jobs.len(); - - sqlx::query!( - "DELETE FROM v2_job_queue WHERE workspace_id = $1 AND suspend = $2", - w_id, - suspend_number - ) - .execute(&mut *tx) - .await?; - - for job in suspended_jobs.iter() { - sqlx::query!( - "DELETE FROM v2_job WHERE id = $1 AND workspace_id = $2", - job.id, - w_id - ) - .execute(&mut *tx) - .await?; - - // Delete related job_perms if exists - sqlx::query!( - "DELETE FROM job_perms WHERE job_id = $1 AND workspace_id = $2", - job.id, - w_id - ) - .execute(&mut *tx) - .await?; - } - - audit_log( - &mut *tx, - &authed, - "jobs.suspend_cancel_batch", - ActionKind::Delete, - &w_id, - Some( - &serde_json::json!({ - "suspend_number": suspend_number, - "job_count": job_count, - "details": format!("Batch cancelled and deleted {} jobs by {}", job_count, &authed.username) - }) - .to_string(), - ), - None, - ) - .await?; - tx.commit().await?; - Ok(StatusCode::OK) -}