diff --git a/app/models/service_retire_task.rb b/app/models/service_retire_task.rb index 70bca689b287..0fc391ef035f 100644 --- a/app/models/service_retire_task.rb +++ b/app/models/service_retire_task.rb @@ -14,5 +14,47 @@ def update_and_notify_parent(*args) end def task_finished + update_attributes(:status => status == 'Ok' ? 'Completed' : 'Failed') + end + + def task_active + update_attributes(:status => 'Active') + end + + def after_request_task_create + update_attributes(:description => get_description) + parent_svc = Service.find_by(:id => options[:src_ids].first) # hacky hacky hack! + _log.info("- creating service tasks for service <#{self.class.name}:#{id}>") + + create_retire_subtasks(parent_svc) + end + + def create_retire_subtasks(parent_service) + tasks = [] + parent_service.service_resources.each do |svc_rsc| + next unless svc_rsc.resource.present? && svc_rsc.resource.respond_to?(:retire_now) + new_task = (svc_rsc.resource.type.demodulize + "RetireTask").constantize.new + + next if svc_rsc.resource_type == "ServiceTemplate" + new_task.options.merge!( + :src_id => svc_rsc.resource.id, + :service_resource_id => svc_rsc.id, + :parent_service_id => parent_service.id, + :parent_task_id => id, + ) + new_task.source = svc_rsc.resource + new_task.request_type = svc_rsc.resource.type.demodulize.downcase + "_retire" + new_task.save! + new_task.after_request_task_create + miq_request.miq_request_tasks << new_task + + tasks << new_task + # nh = self.attributes.dup + # %w(id created_on updated_on type state status message).each { |key| nh.delete(key) } + # nh['options'] = self.options.dup + # nh['options'].delete(:child_tasks) + end + tasks.each(&:deliver_to_automate) + tasks end end