From db07016b9cd49a50eef10539f1bab5cec98bd50d Mon Sep 17 00:00:00 2001 From: Adam Grare Date: Mon, 4 Jun 2018 15:18:45 -0400 Subject: [PATCH] Use MiqSchedule for delayed MiqRequest execution Instead of using MiqQueue with deliver_on to run an MiqRequest later, create a run-once MiqSchedule record. --- app/models/miq_request.rb | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/app/models/miq_request.rb b/app/models/miq_request.rb index abe8e981e616..4e301af61914 100644 --- a/app/models/miq_request.rb +++ b/app/models/miq_request.rb @@ -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 + date = get_option(:schedule_time).utc rescue nil + + MiqSchedule.create!( + :name => "Request scheduled", + :description => "Request scheduled", + :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 => date, + :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, @@ -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