diff --git a/app/models/mixins/process_tasks_mixin.rb b/app/models/mixins/process_tasks_mixin.rb index 879fcc240d1..efec812e66c 100644 --- a/app/models/mixins/process_tasks_mixin.rb +++ b/app/models/mixins/process_tasks_mixin.rb @@ -1,3 +1,4 @@ +require 'manageiq-api-client' module ProcessTasksMixin extend ActiveSupport::Concern include RetirementMixin @@ -94,9 +95,6 @@ def invoke_tasks_remote(options) MiqQueue.submit_job(q_hash) next end - - msg = "'#{options[:task]}' successfully initiated for remote VMs: #{ids.sort.inspect}" - task_audit_event(:success, options, :message => msg) end end @@ -123,16 +121,26 @@ def invoke_api_tasks(api_client, remote_options) 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) - rescue NoMethodError, ManageIQ::API::Client::ResourceNotFound => err + msg = "'#{remote_options[:task]}' successfully initiated on remote object #{obj.class}: #{id} for collection #{collection_name}" + task_audit_event(:success, remote_options, :message => msg) + rescue StandardError => err + msg = "'#{remote_options[:task]}' failed on remote object #{id} for collection #{collection_name}" + task_audit_event(:failure, remote_options, :target_id => id, :message => msg) _log.error(err.message) + raise err unless err.is_a?(NoMethodError) || err.is_a?(ManageIQ::API::Client::ResourceNotFound) end end else _log.info("Invoking task #{action} on collection #{collection_name}, with args #{post_args}") begin collection.send(action, post_args) - rescue NoMethodError => err + msg = "'#{remote_options[:task]}' successfully initiated on collection #{collection_name}, with args #{post_args}" + task_audit_event(:success, remote_options, :message => msg) + rescue StandardError => err + msg = "'#{remote_options[:task]}' failed on remote collection #{collection_name}, with args #{post_args}" + task_audit_event(:failure, remote_options, :message => msg) _log.error(err.message) + raise err unless err.is_a?(NoMethodError) end end end