Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid raising and re-queueing when the remote resource is not found #17745

Merged
merged 1 commit into from
Aug 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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