Skip to content

Commit

Permalink
Add child retirement task methods
Browse files Browse the repository at this point in the history
  • Loading branch information
d-m-u committed Apr 10, 2018
1 parent 3d19c53 commit 6a6b4b9
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions app/models/service_retire_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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])
_log.info("- creating service tasks for service <#{self.class.name}:#{id}>")

create_retire_subtasks(parent_svc)
end

def create_retire_subtasks(parent_service)
parent_service.service_resources.collect do |svc_rsc|
next unless svc_rsc.resource.present? && svc_rsc.resource.respond_to?(:retire_now)
next if svc_rsc.resource_type == "ServiceTemplate" &&
!self.class.include_service_template?(self,
svc_rsc.resource.id,
parent_service)
nh = attributes.except("id", "created_on", "updated_on", "type", "state", "status", "message")
nh['options'] = options.except(:child_tasks)
# Initial Options[:dialog] to an empty hash so we do not pass down dialog values to child services tasks
nh['options'][:dialog] = {}

new_task = (svc_rsc.resource.type.demodulize + "RetireTask").constantize.new(nh)
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
new_task.deliver_to_automate
new_task
end.compact!
end
end

0 comments on commit 6a6b4b9

Please sign in to comment.