Skip to content

Commit

Permalink
Update with review suggestions.
Browse files Browse the repository at this point in the history
  • Loading branch information
simi committed Nov 13, 2023
1 parent ecbedf5 commit 5821d27
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 7 deletions.
5 changes: 4 additions & 1 deletion app/jobs/rstuf/check_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@ class Rstuf::CheckJob < Rstuf::ApplicationJob
queue_with_priority PRIORITIES.fetch(:push)

def perform(task_id)
case Rstuf::Client.task_status(task_id)
case status = Rstuf::Client.task_status(task_id)
when "SUCCESS"
# no-op, all good
when "FAILURE"
raise FailureException, "RSTUF job failed"
when "PENDING"
raise RetryException
else
Rails.logger.info "RSTUF job returned unexpected state #{status}"
raise RetryException
end
end
Expand Down
4 changes: 2 additions & 2 deletions app/models/deletion.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ def expire_cache
def remove_from_index
version.update!(indexed: false, yanked_at: Time.now.utc)
reindex
Rstuf::RemoveJob.perform_later(version: version)
Rstuf::RemoveJob.perform_later(version:)
end

def restore_to_index
version.update!(indexed: true, yanked_at: nil, yanked_info_checksum: nil)
reindex
Rstuf::AddJob.perform_later(version: version)
Rstuf::AddJob.perform_later(version:)
end

def reindex
Expand Down
2 changes: 1 addition & 1 deletion config/initializers/rstuf.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'rstuf'

if ENV['RSTUF_API_URL']
if ENV['RSTUF_API_URL'].presence
Rstuf.base_url = ENV['RSTUF_API_URL']
Rstuf.enabled = true
Rstuf.wait_for = 10.seconds
Expand Down
1 change: 1 addition & 0 deletions lib/rstuf/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def self.connection
Faraday.new(url: Rstuf.base_url) do |f|
f.request :json
f.response :json
f.response :logger, Rails.logger
end
end

Expand Down
12 changes: 11 additions & 1 deletion test/jobs/rstuf/check_job_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class Rstuf::CheckJobTest < ActiveJob::TestCase
end
end

test "perform raises a retry exception on retry state and retries" do
test "perform raises a retry exception on pending state and retries" do
retry_response = { "data" => { "state" => "PENDING" } }
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" })
Expand All @@ -37,6 +37,16 @@ class Rstuf::CheckJobTest < ActiveJob::TestCase
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}")
.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

teardown do
teardown_rstuf
end
Expand Down
2 changes: 1 addition & 1 deletion test/models/deletion_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class DeletionTest < ActiveSupport::TestCase
end

should "enqueue rstuf removal" do
assert_enqueued_jobs 1, only: Rstuf::RemoveJob do
assert_enqueued_with(job: Rstuf::RemoveJob, args: [{ version: @version }]) do
delete_gem
end
end
Expand Down
2 changes: 1 addition & 1 deletion test/models/pusher_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,7 @@ def two_cert_chain(signing_key:, root_not_before: Time.current, cert_not_before:
end

should "enqueue rstuf addition" do
assert_enqueued_jobs 1, only: Rstuf::AddJob do
assert_enqueued_with(job: Rstuf::AddJob, args: [{ version: @cutter.version }]) do
@cutter.save
end
end
Expand Down

0 comments on commit 5821d27

Please sign in to comment.