mirror of
https://github.com/windmill-labs/windmill.git
synced 2026-08-24 08:01:38 +00:00
jobs update
This commit is contained in:
@@ -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<DB>,
|
||||
Path((w_id, job_id, suspend_number)): Path<(String, Uuid, i32)>,
|
||||
) -> error::Result<StatusCode> {
|
||||
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<DB>,
|
||||
Path((w_id, job_id, suspend_number)): Path<(String, Uuid, i32)>,
|
||||
) -> error::Result<StatusCode> {
|
||||
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<DB>,
|
||||
Path((w_id, suspend_number)): Path<(String, i32)>,
|
||||
) -> error::Result<StatusCode> {
|
||||
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<DB>,
|
||||
Path((w_id, suspend_number)): Path<(String, i32)>,
|
||||
) -> error::Result<StatusCode> {
|
||||
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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user