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 5, 2018
1 parent 4acfef6 commit 1d26a14
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions app/models/service_retire_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,43 @@ 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_id])
_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
end
tasks.each(&:deliver_to_automate)
tasks
end
end

0 comments on commit 1d26a14

Please sign in to comment.