Skip to content

Commit

Permalink
Use MiqSchedule for delayed MiqRequest execution
Browse files Browse the repository at this point in the history
Instead of using MiqQueue with deliver_on to run an MiqRequest later,
create a run-once MiqSchedule record.
  • Loading branch information
agrare committed Jun 5, 2018
1 parent a9ea250 commit 08a2adf
Showing 1 changed file with 18 additions and 3 deletions.
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

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

0 comments on commit 08a2adf

Please sign in to comment.