From a6343cfb71f22b050156bedff73eed55cd33190e Mon Sep 17 00:00:00 2001 From: Brandon Dunne Date: Mon, 23 Jul 2018 14:38:46 -0400 Subject: [PATCH] Avoid raising and re-queueing when the remote resource is not found Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1599754 --- Gemfile | 2 +- app/models/mixins/process_tasks_mixin.rb | 11 ++++++++--- spec/models/mixins/process_tasks_mixin_spec.rb | 13 +++++++++++++ 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/Gemfile b/Gemfile index fe2f2a1162e..3dcd940e98b 100644 --- a/Gemfile +++ b/Gemfile @@ -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__) diff --git a/app/models/mixins/process_tasks_mixin.rb b/app/models/mixins/process_tasks_mixin.rb index e66d9817a0f..61e37036e49 100644 --- a/app/models/mixins/process_tasks_mixin.rb +++ b/app/models/mixins/process_tasks_mixin.rb @@ -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}") diff --git a/spec/models/mixins/process_tasks_mixin_spec.rb b/spec/models/mixins/process_tasks_mixin_spec.rb index 289d578a747..fb796f6af4a 100644 --- a/spec/models/mixins/process_tasks_mixin_spec.rb +++ b/spec/models/mixins/process_tasks_mixin_spec.rb @@ -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) }