Skip to content

Commit 4c88dd6

Browse files
kairoaraujosimi
authored andcommitted
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.
1 parent 7f52ae7 commit 4c88dd6

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

app/jobs/rstuf/check_job.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def perform(task_id)
1414
raise FailureException, "RSTUF job failed, please check payload and retry"
1515
when "ERRORED", "REVOKED", "REJECTED"
1616
raise ErrorException, "RSTUF internal problem, please check RSTUF health"
17-
when "PENDING", "RUNNING", "RECEIVED", "STARTED"
17+
when "PENDING", "PRE_RUN", "RUNNING", "RECEIVED", "STARTED"
1818
raise RetryException
1919
else
2020
Rails.logger.info "RSTUF job returned unexpected state #{status}"

test/jobs/rstuf/check_job_test.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,16 @@ class Rstuf::CheckJobTest < ActiveJob::TestCase
4747
end
4848
end
4949

50+
test "perform raises a retry exception on pre_run state and retries" do
51+
retry_response = { "data" => { "state" => "PRE_RUN" } }
52+
stub_request(:get, "#{Rstuf.base_url}/api/v1/task/?task_id=#{@task_id}")
53+
.to_return(status: 200, body: retry_response.to_json, headers: { "Content-Type" => "application/json" })
54+
55+
assert_enqueued_with(job: Rstuf::CheckJob, args: [@task_id]) do
56+
Rstuf::CheckJob.perform_now(@task_id)
57+
end
58+
end
59+
5060
test "perform raises a retry exception on retry state and retries" do
5161
retry_response = { "data" => { "state" => "UNKNOWN" } }
5262
stub_request(:get, "#{Rstuf.base_url}/api/v1/task/?task_id=#{@task_id}")

0 commit comments

Comments
 (0)