From 0dfdf8fa1be88d601f7dbf7b348aaf8a3ae8e2fd Mon Sep 17 00:00:00 2001 From: Ruben Fiszel Date: Sun, 27 Aug 2023 14:40:20 +0200 Subject: [PATCH] fix: canceling jobs --- backend/tests/fixtures/base.sql | 4 ++++ backend/tests/worker.rs | 4 ++-- backend/windmill-api/src/jobs.rs | 20 ++++++++++++++++++++ backend/windmill-common/src/error.rs | 8 +++++++- backend/windmill-queue/src/jobs.rs | 7 ++++--- 5 files changed, 37 insertions(+), 6 deletions(-) diff --git a/backend/tests/fixtures/base.sql b/backend/tests/fixtures/base.sql index 71b51d7cb5..16c0d7bb72 100644 --- a/backend/tests/fixtures/base.sql +++ b/backend/tests/fixtures/base.sql @@ -11,6 +11,10 @@ INSERT INTO usr(workspace_id, email, username, is_admin, role) VALUES INSERT INTO workspace_key(workspace_id, kind, key) VALUES ('test-workspace', 'cloud', 'test-key'); + +INSERT INTO workspace_settings (workspace_id) VALUES + ('test-workspace'); + insert INTO token(token, email, label, super_admin) VALUES ('SECRET_TOKEN', 'test@windmill.dev', 'test token', true); INSERT INTO public.script(workspace_id, created_by, content, schema, summary, description, path, hash, language, lock) VALUES ( diff --git a/backend/tests/worker.rs b/backend/tests/worker.rs index 8f22c97ad4..ab7e9565a8 100644 --- a/backend/tests/worker.rs +++ b/backend/tests/worker.rs @@ -2549,14 +2549,14 @@ async fn test_flow_lock_all(db: Pool) { assert!(matches!( m.value, windmill_api_client::types::FlowModuleValue::RawScript(RawScript { - language: windmill_api_client::types::RawScriptLanguage::Deno | windmill_api_client::types::RawScriptLanguage::Bash, + language: windmill_api_client::types::RawScriptLanguage::Bash, lock: Some(ref lock), .. }) if lock == "") || matches!( m.value, windmill_api_client::types::FlowModuleValue::RawScript(RawScript{ - language: windmill_api_client::types::RawScriptLanguage::Go | windmill_api_client::types::RawScriptLanguage::Python3, + language: windmill_api_client::types::RawScriptLanguage::Go | windmill_api_client::types::RawScriptLanguage::Python3 | windmill_api_client::types::RawScriptLanguage::Deno, lock: Some(ref lock), .. }) if lock.len() > 0) diff --git a/backend/windmill-api/src/jobs.rs b/backend/windmill-api/src/jobs.rs index e93d9a8684..6f783d485c 100644 --- a/backend/windmill-api/src/jobs.rs +++ b/backend/windmill-api/src/jobs.rs @@ -673,6 +673,26 @@ async fn cancel_all( Ok(Json(uuids)) } +// #[derive(Serialize, Debug, FromRow)] +// struct QueueStats { +// database_length: i64, +// } + +// async fn count_waiting_for_executors( +// Extension(db): Extension, +// Path(w_id): Path, +// ) -> error::JsonResult { +// Ok(Json( +// sqlx::query_as!( +// QueueStats, +// "SELECT coalesce(COUNT(*), 0) as \"database_length!\" FROM queue WHERE workspace_id = $1", +// w_id +// ) +// .fetch_one(&db) +// .await?, +// )) +// } + #[derive(Serialize, Debug, FromRow)] struct QueueStats { database_length: i64, diff --git a/backend/windmill-common/src/error.rs b/backend/windmill-common/src/error.rs index 7bfc2c8177..0dd9027fea 100644 --- a/backend/windmill-common/src/error.rs +++ b/backend/windmill-common/src/error.rs @@ -94,7 +94,13 @@ impl IntoResponse for Error { } _ => axum::http::StatusCode::INTERNAL_SERVER_ERROR, }; - tracing::error!(error = e.to_string()); + + if matches!(status, axum::http::StatusCode::NOT_FOUND) { + tracing::warn!(not_found = e.to_string()); + } else { + tracing::error!(error = e.to_string()); + }; + axum::response::Response::builder() .header("Content-Type", "text/plain") .status(status) diff --git a/backend/windmill-queue/src/jobs.rs b/backend/windmill-queue/src/jobs.rs index 1cb197248b..1a766e9f28 100644 --- a/backend/windmill-queue/src/jobs.rs +++ b/backend/windmill-queue/src/jobs.rs @@ -140,9 +140,9 @@ pub async fn cancel_job<'c: 'async_recursion>( return Ok((tx, None)); } let job_running = job_running.unwrap(); - if job_running.running - && job_running.job_kind != JobKind::Flow - && job_running.job_kind != JobKind::FlowPreview + + if ((!job_running.running && job_running.root_job.is_none()) + || (job_running.job_kind == JobKind::Flow || job_running.job_kind == JobKind::FlowPreview)) && !force_cancel { sqlx::query!( @@ -362,6 +362,7 @@ pub async fn add_completed_job( .await .map_err(|e| Error::InternalErr(format!("Could not add completed job {job_id}: {e}")))?; + // tracing::error!("Added completed job {:#?}", queued_job); tx = delete_job(tx, &queued_job.workspace_id, job_id).await?; if !queued_job.is_flow_step && queued_job.schedule_path.is_some()