Skip to content

Commit

Permalink
Add new RSTUF state PRE_RUN to check job
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
kairoaraujo authored and simi committed Nov 1, 2024
1 parent 7f52ae7 commit 4c88dd6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/jobs/rstuf/check_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
10 changes: 10 additions & 0 deletions test/jobs/rstuf/check_job_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand Down

0 comments on commit 4c88dd6

Please sign in to comment.