Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add child retirement task methods #17234

Merged
merged 2 commits into from
Apr 17, 2018

Conversation

d-m-u
Copy link
Contributor

@d-m-u d-m-u commented Mar 29, 2018

The service retirement needs tasks and requests for each child item and this is the creation of those.

Depends on #17255

@miq-bot miq-bot added the wip label Mar 29, 2018
@d-m-u
Copy link
Contributor Author

d-m-u commented Apr 2, 2018

@miq-bot add_label enhancement

@d-m-u d-m-u force-pushed the adding_service_task_retirement branch from 82758f2 to 95c16f5 Compare April 3, 2018 13:45
@d-m-u
Copy link
Contributor Author

d-m-u commented Apr 3, 2018

@tinaafitz could you review please

miq_request.miq_request_tasks << new_task

tasks << new_task
# nh = self.attributes.dup
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tinaafitz I don't think I care about the self.attributes stuff, right? This and the next three lines can go bye bye?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@d-m-u That is correct. You can remove all of the nh references.

:parent_service_id => parent_service.id,
:parent_task_id => id,
)
# don't believe the next two lines are necessary
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@d-m-u That is correct. The default state = Pending and the default status = 'Ok'

@d-m-u d-m-u force-pushed the adding_service_task_retirement branch from 95c16f5 to b675c7e Compare April 3, 2018 14:12

def after_request_task_create
update_attributes(:description => get_description)
parent_svc = Service.find_by(:id => options[:src_ids].first) # hacky hacky hack!
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tinaafitz one more thing: can we fix this as a later item?

@d-m-u d-m-u force-pushed the adding_service_task_retirement branch from b675c7e to 54f4160 Compare April 3, 2018 14:22
@d-m-u
Copy link
Contributor Author

d-m-u commented Apr 3, 2018

@miq-bot add_label retirement

@d-m-u
Copy link
Contributor Author

d-m-u commented Apr 5, 2018

@bdunne any chance you could 👀 on this for me please?

@d-m-u d-m-u changed the title [WIP] Add child retirement task methods Add child retirement task methods Apr 5, 2018
@miq-bot miq-bot removed the wip label Apr 5, 2018
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"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be above the new_task = to potentially avoid allocating new objects

new_task = (svc_rsc.resource.type.demodulize + "RetireTask").constantize.new

next if svc_rsc.resource_type == "ServiceTemplate"
new_task.options.merge!(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does a new_task have default options that you are merging into? If not, you can create! rather than new, merge options, set relations and save!.


tasks << new_task
end
tasks.each(&:deliver_to_automate)
Copy link
Member

@bdunne bdunne Apr 5, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this move into the each block above to avoid enumerating it twice?
image


def create_retire_subtasks(parent_service)
tasks = []
parent_service.service_resources.each do |svc_rsc|
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The .each here could become collect with compact at the end, then you don't need the tasks array above

@d-m-u d-m-u force-pushed the adding_service_task_retirement branch from 1d26a14 to a22e2e4 Compare April 9, 2018 12:09
Copy link
Member

@bdunne bdunne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any plans of adding tests?

next unless svc_rsc.resource.present? && svc_rsc.resource.respond_to?(:retire_now)
next if svc_rsc.resource_type == "ServiceTemplate"

nh = parent_service_task.attributes.dup
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should be able to:

nh = parent_service_task.attributes.except(:id, :created_on, etc...)

nh = parent_service_task.attributes.dup
%w(id created_on updated_on type state status message).each { |key| nh.delete(key) }
nh['options'] = parent_service_task.options.dup
nh['options'].delete(:child_tasks)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

child_svc_rsc.resource.id,
parent_service)
new_task = (svc_rsc.resource.type.demodulize + "RetireTask").constantize.new(nh)
new_task.options.merge!(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't this live in the new call? Is options initialized as a non-empty hash?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, it is, yes.

@d-m-u d-m-u changed the title Add child retirement task methods [WIP] Add child retirement task methods Apr 9, 2018
@d-m-u d-m-u force-pushed the adding_service_task_retirement branch from a22e2e4 to 53407c1 Compare April 9, 2018 16:44
@miq-bot miq-bot added the wip label Apr 9, 2018
@d-m-u d-m-u force-pushed the adding_service_task_retirement branch from 53407c1 to 5ffc94b Compare April 9, 2018 16:48
new_task.save!
new_task.after_request_task_create
miq_request.miq_request_tasks << new_task
new_task.deliver_to_automate unless new_task.nil?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would new_task be nil?

@d-m-u d-m-u force-pushed the adding_service_task_retirement branch 3 times, most recently from 40061f7 to 02b0a68 Compare April 10, 2018 14:56
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] = {}
next if svc_rsc.resource_type == "ServiceTemplate" &&
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be moved up closer to the other nexts? If so, it could potentially avoid allocating extra objects for nh

new_task.save!
new_task.after_request_task_create
miq_request.miq_request_tasks << new_task
new_task.deliver_to_automate
Copy link
Member

@bdunne bdunne Apr 10, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the collect is expected to be an array of tasks, you'll need new_task to be the last line in the block. As it is, this will collect whatever deliver_to_automate returns

@d-m-u d-m-u force-pushed the adding_service_task_retirement branch from 02b0a68 to 468e8af Compare April 10, 2018 18:25
@d-m-u d-m-u force-pushed the adding_service_task_retirement branch from 468e8af to 9f3f6fb Compare April 10, 2018 18:52
@miq-bot
Copy link
Member

miq-bot commented Apr 10, 2018

Checked commits d-m-u/manageiq@6a6b4b9~...9f3f6fb with ruby 2.3.3, rubocop 0.52.1, haml-lint 0.20.0, and yamllint 1.10.0
3 files checked, 2 offenses detected

spec/factories/miq_request_task.rb

@d-m-u d-m-u changed the title [WIP] Add child retirement task methods Add child retirement task methods Apr 10, 2018
@miq-bot miq-bot removed the wip label Apr 10, 2018
Copy link
Member

@tinaafitz tinaafitz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@d-m-u Looks good.

@mkanoor mkanoor merged commit 2c945ce into ManageIQ:master Apr 17, 2018
@mkanoor mkanoor added this to the Sprint 84 Ending Apr 23, 2018 milestone Apr 17, 2018
@d-m-u d-m-u deleted the adding_service_task_retirement branch October 26, 2018 18:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants