From 3cd1a55768c323bc99999efdbffd6173bc53da7a Mon Sep 17 00:00:00 2001 From: Lee Smet Date: Mon, 8 Sep 2025 13:37:42 +0200 Subject: [PATCH] Fix job status transitions Signed-off-by: Lee Smet --- src/router.rs | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/service.rs | 8 ++++---- 2 files changed, 55 insertions(+), 4 deletions(-) diff --git a/src/router.rs b/src/router.rs index b142324..6145ae8 100644 --- a/src/router.rs +++ b/src/router.rs @@ -448,6 +448,23 @@ async fn deliver_one( MessageStatus::Processed, ) .await; + // Also mark job as Finished so the flow can progress (ignore invalid transitions) + let _ = service_poll + .update_job_status_unchecked( + context_id, caller_id, job_id, JobStatus::Finished, + ) + .await; + let _ = service_poll + .append_message_logs( + context_id, + caller_id, + id, + vec![format!( + "Updated job {} status to Finished (sync)", job_id + )], + ) + .await; + // Existing log about storing result let _ = service_poll .append_message_logs( context_id, @@ -481,6 +498,23 @@ async fn deliver_one( MessageStatus::Processed, ) .await; + // Also mark job as Error so the flow can handle failure (ignore invalid transitions) + let _ = service_poll + .update_job_status_unchecked( + context_id, caller_id, job_id, JobStatus::Error, + ) + .await; + let _ = service_poll + .append_message_logs( + context_id, + caller_id, + id, + vec![format!( + "Updated job {} status to Error (sync)", job_id + )], + ) + .await; + // Existing log about storing result let _ = service_poll .append_message_logs( context_id, @@ -516,6 +550,23 @@ async fn deliver_one( MessageStatus::Processed, ) .await; + // Also mark job as Finished so the flow can progress (ignore invalid transitions) + let _ = service_poll + .update_job_status_unchecked( + context_id, caller_id, job_id, JobStatus::Finished, + ) + .await; + let _ = service_poll + .append_message_logs( + context_id, + caller_id, + id, + vec![format!( + "Updated job {} status to Finished (sync)", job_id + )], + ) + .await; + // Existing log about storing result let _ = service_poll .append_message_logs( context_id, diff --git a/src/service.rs b/src/service.rs index d586830..8403a5a 100644 --- a/src/service.rs +++ b/src/service.rs @@ -672,10 +672,10 @@ impl AppService { let allowed = match current { JobStatus::Dispatched => matches!( new_status, - JobStatus::WaitingForPrerequisites | JobStatus::Started | JobStatus::Error + JobStatus::WaitingForPrerequisites | JobStatus::Started | JobStatus::Finished | JobStatus::Error ), JobStatus::WaitingForPrerequisites => { - matches!(new_status, JobStatus::Started | JobStatus::Error) + matches!(new_status, JobStatus::Started | JobStatus::Finished | JobStatus::Error) } JobStatus::Started => matches!(new_status, JobStatus::Finished | JobStatus::Error), JobStatus::Finished | JobStatus::Error => false, @@ -714,10 +714,10 @@ impl AppService { let allowed = match current { JobStatus::Dispatched => matches!( new_status, - JobStatus::WaitingForPrerequisites | JobStatus::Started | JobStatus::Error + JobStatus::WaitingForPrerequisites | JobStatus::Started | JobStatus::Finished | JobStatus::Error ), JobStatus::WaitingForPrerequisites => { - matches!(new_status, JobStatus::Started | JobStatus::Error) + matches!(new_status, JobStatus::Started | JobStatus::Finished | JobStatus::Error) } JobStatus::Started => matches!(new_status, JobStatus::Finished | JobStatus::Error), JobStatus::Finished | JobStatus::Error => false,