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

Use MiqSchedule for delayed MiqRequest execution #17520

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions app/models/miq_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -420,11 +420,27 @@ def task_check_on_execute
def execute
task_check_on_execute

deliver_on = nil
if get_option(:schedule_type) == "schedule"
deliver_on = get_option(:schedule_time).utc rescue nil
start_time = get_option(:schedule_time).utc rescue nil
Copy link
Member Author

Choose a reason for hiding this comment

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

Note to self what if start_time is in the past (aka scheduled in the future but approval took longer)

Copy link
Member

Choose a reason for hiding this comment

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

I would recommend that we refactor this line. The classic UI sets get_option(:schedule_time) to a ActiveSupport::TimeWithZone object which supports the utc call.

I suspect that if this is set from the API or some other means it would set the time as a string in which case the code will silently error and use nil. It is also a good opportunity to get rid of the inline rescue as well.

Copy link
Member

@bdunne bdunne Jun 7, 2018

Choose a reason for hiding this comment

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

Fixed by: bb29981


MiqSchedule.create!(
:name => description,
:description => description,
:sched_action => {:method => "queue_create_request_tasks"},
:filter => MiqExpression.new("=" => {"field" => "MiqRequest-id", "value" => id}),
:towhat => self.class.name,
:run_at => {
:interval => {:unit => "once"},
:start_time => start_time,
:tz => "UTC",
},
)
else
queue_create_request_tasks
end
end

def queue_create_request_tasks
# self.create_request_tasks
MiqQueue.put(
:class_name => self.class.name,
Expand All @@ -434,7 +450,6 @@ def execute
:role => my_role(:create_request_tasks),
:tracking_label => tracking_label_id,
:msg_timeout => 3600,
:deliver_on => deliver_on
)
end

Expand Down