From 4c88dd61a69ab32b3b2e721f7b9959bd91ca888e Mon Sep 17 00:00:00 2001 From: Kairo Araujo Date: Sun, 13 Oct 2024 10:01:03 +0200 Subject: [PATCH] Add new RSTUF state `PRE_RUN` to check job Add a new RSTUF state `PRE_RUN` to check the job. This state is right after being received by the RSTUF Worker and should retry. --- app/jobs/rstuf/check_job.rb | 2 +- test/jobs/rstuf/check_job_test.rb | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/app/jobs/rstuf/check_job.rb b/app/jobs/rstuf/check_job.rb index c66da399fe2..82e2bc1b7c8 100644 --- a/app/jobs/rstuf/check_job.rb +++ b/app/jobs/rstuf/check_job.rb @@ -14,7 +14,7 @@ def perform(task_id) raise FailureException, "RSTUF job failed, please check payload and retry" when "ERRORED", "REVOKED", "REJECTED" raise ErrorException, "RSTUF internal problem, please check RSTUF health" - when "PENDING", "RUNNING", "RECEIVED", "STARTED" + when "PENDING", "PRE_RUN", "RUNNING", "RECEIVED", "STARTED" raise RetryException else Rails.logger.info "RSTUF job returned unexpected state #{status}" diff --git a/test/jobs/rstuf/check_job_test.rb b/test/jobs/rstuf/check_job_test.rb index d45a535de96..9298770393d 100644 --- a/test/jobs/rstuf/check_job_test.rb +++ b/test/jobs/rstuf/check_job_test.rb @@ -47,6 +47,16 @@ class Rstuf::CheckJobTest < ActiveJob::TestCase end end + test "perform raises a retry exception on pre_run state and retries" do + retry_response = { "data" => { "state" => "PRE_RUN" } } + stub_request(:get, "#{Rstuf.base_url}/api/v1/task/?task_id=#{@task_id}") + .to_return(status: 200, body: retry_response.to_json, headers: { "Content-Type" => "application/json" }) + + assert_enqueued_with(job: Rstuf::CheckJob, args: [@task_id]) do + Rstuf::CheckJob.perform_now(@task_id) + end + end + test "perform raises a retry exception on retry state and retries" do retry_response = { "data" => { "state" => "UNKNOWN" } } stub_request(:get, "#{Rstuf.base_url}/api/v1/task/?task_id=#{@task_id}")