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 3, 2018
1 parent c6c282a commit b675c7e
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].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

0 comments on commit b675c7e

Please sign in to comment.