-
Notifications
You must be signed in to change notification settings - Fork 897
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
Add child retirement task methods #17234
Conversation
@miq-bot add_label enhancement |
82758f2
to
95c16f5
Compare
@tinaafitz could you review please |
app/models/service_retire_task.rb
Outdated
miq_request.miq_request_tasks << new_task | ||
|
||
tasks << new_task | ||
# nh = self.attributes.dup |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
app/models/service_retire_task.rb
Outdated
:parent_service_id => parent_service.id, | ||
:parent_task_id => id, | ||
) | ||
# don't believe the next two lines are necessary |
There was a problem hiding this comment.
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'
95c16f5
to
b675c7e
Compare
app/models/service_retire_task.rb
Outdated
|
||
def after_request_task_create | ||
update_attributes(:description => get_description) | ||
parent_svc = Service.find_by(:id => options[:src_ids].first) # hacky hacky hack! |
There was a problem hiding this comment.
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?
b675c7e
to
54f4160
Compare
@miq-bot add_label retirement |
54f4160
to
1d26a14
Compare
@bdunne any chance you could 👀 on this for me please? |
app/models/service_retire_task.rb
Outdated
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" |
There was a problem hiding this comment.
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
app/models/service_retire_task.rb
Outdated
new_task = (svc_rsc.resource.type.demodulize + "RetireTask").constantize.new | ||
|
||
next if svc_rsc.resource_type == "ServiceTemplate" | ||
new_task.options.merge!( |
There was a problem hiding this comment.
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!
.
app/models/service_retire_task.rb
Outdated
|
||
tasks << new_task | ||
end | ||
tasks.each(&:deliver_to_automate) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
app/models/service_retire_task.rb
Outdated
|
||
def create_retire_subtasks(parent_service) | ||
tasks = [] | ||
parent_service.service_resources.each do |svc_rsc| |
There was a problem hiding this comment.
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
1d26a14
to
a22e2e4
Compare
There was a problem hiding this 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?
app/models/service_retire_task.rb
Outdated
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 |
There was a problem hiding this comment.
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...)
app/models/service_retire_task.rb
Outdated
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here
app/models/service_retire_task.rb
Outdated
child_svc_rsc.resource.id, | ||
parent_service) | ||
new_task = (svc_rsc.resource.type.demodulize + "RetireTask").constantize.new(nh) | ||
new_task.options.merge!( |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately, it is, yes.
a22e2e4
to
53407c1
Compare
53407c1
to
5ffc94b
Compare
app/models/service_retire_task.rb
Outdated
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? |
There was a problem hiding this comment.
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
?
40061f7
to
02b0a68
Compare
app/models/service_retire_task.rb
Outdated
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" && |
There was a problem hiding this comment.
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 next
s? 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 |
There was a problem hiding this comment.
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
02b0a68
to
468e8af
Compare
468e8af
to
9f3f6fb
Compare
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 spec/factories/miq_request_task.rb
|
There was a problem hiding this 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.
The service retirement needs tasks and requests for each child item and this is the creation of those.
Depends on #17255