Skip to content

Commit

Permalink
Avoid raising and re-queueing when the remote resource is not found
Browse files Browse the repository at this point in the history
  • Loading branch information
bdunne committed Aug 6, 2018
1 parent 97b4735 commit a6343cf
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ gem "inifile", "~>3.0", :require => false
gem "kubeclient", "~>2.4", :require => false # For scaling pods at runtime
gem "linux_admin", "~>1.2.1", :require => false
gem "log_decorator", "~>0.1", :require => false
gem "manageiq-api-client", "~>0.3.0", :require => false
gem "manageiq-api-client", "~>0.3.1", :require => false
gem "manageiq-messaging", :require => false, :git => "https://github.com/ManageIQ/manageiq-messaging", :branch => "master"
gem "memoist", "~>0.15.0", :require => false
gem "mime-types", "~>3.0", :path => File.expand_path("mime-types-redirector", __dir__)
Expand Down
11 changes: 8 additions & 3 deletions app/models/mixins/process_tasks_mixin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,14 @@ def invoke_api_tasks(api_client, remote_options)

if resource_ids.present?
resource_ids.each do |id|
obj = collection.find(id)
_log.info("Invoking task #{action} on collection #{collection_name}, object #{obj.id}, with args #{post_args}")
obj.send(action, post_args)
begin
obj = collection.find(id)
rescue ManageIQ::API::Client::ResourceNotFound => err
_log.error(err.message)
else
_log.info("Invoking task #{action} on collection #{collection_name}, object #{obj.id}, with args #{post_args}")
obj.send(action, post_args)
end
end
else
_log.info("Invoking task #{action} on collection #{collection_name}, with args #{post_args}")
Expand Down
13 changes: 13 additions & 0 deletions spec/models/mixins/process_tasks_mixin_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,19 @@ def test_method
end
end

it "with missing remote resource does not raise" do
resource0 = double("resource0", :id => 0)
expect(api_collection).to receive(:find).with(0).and_raise(ManageIQ::API::Client::ResourceNotFound, "Couldn't find resource with 'id' [0]")
options = {
:ids => [0],
:task => "the_task",
:args => {:some => "args"}
}
expect(resource0).not_to receive(:the_task)

expect { test_class.invoke_api_tasks(api_connection, options) }.not_to raise_error
end

context "when passed resource ids" do
let(:resource0) { double("resource0", :id => 0) }
let(:resource1) { double("resource1", :id => 1) }
Expand Down

0 comments on commit a6343cf

Please sign in to comment.