diff --git a/app/controllers/application_controller/wait_for_task.rb b/app/controllers/application_controller/wait_for_task.rb index d7d26a92357..c3f947aa9a6 100644 --- a/app/controllers/application_controller/wait_for_task.rb +++ b/app/controllers/application_controller/wait_for_task.rb @@ -11,25 +11,23 @@ def wait_for_task @edit = session[:edit] # If in edit, need to preserve @edit object raise Forbidden, _('Invalid input for "wait_for_task".') unless params[:task_id] - session[:async] ||= {} - session[:async][:interval] ||= 1000 # Default interval to 1 second - async_params = params[:async_params] || session[:async][:params] || {} + async_interval = params[:async_interval] || 1000 # Default interval to 1 second + async_params = params[:async_params] || session[:async][:params] if MiqTask.find(params[:task_id].to_i).state != "Finished" # Task not done --> retry - browser_refresh_task(params[:task_id], async_params) + browser_refresh_task(params[:task_id], async_params, async_interval) else # Task done async_params.each { |k, v| @_params[k] = v } # Merge in the original params and send(async_params[:action]) # call the orig. method end end - def browser_refresh_task(task_id, async_params, should_flash: false) - session[:async][:interval] += 250 if session[:async][:interval] < 5000 # Slowly move up to 5 second retries - session_interval = params[:async_interval] || session[:async][:interval] + def browser_refresh_task(task_id, async_params, async_interval, should_flash: false) + async_interval += 250 if async_interval < 5000 # Slowly move up to 5 second retries render :update do |page| page << javascript_prologue - ajax_call = remote_function(:url => {:action => 'wait_for_task', :task_id => task_id, :async_params => async_params}) - page << "setTimeout(\"#{ajax_call}\", #{session_interval});" + ajax_call = remote_function(:url => {:action => 'wait_for_task', :task_id => task_id, :async_params => async_params, :async_interval => :async_interval}) + page << "setTimeout(\"#{ajax_call}\", #{async_interval});" page.replace("flash_msg_div", :partial => "layouts/flash_msg") if should_flash page << "miqScrollTop();" if @flash_array.present? end @@ -45,8 +43,7 @@ def browser_refresh_task(task_id, async_params, should_flash: false) # def initiate_wait_for_task(options = {}) task_id = options[:task_id] - session[:async] ||= {} - session[:async][:interval] ||= 1000 # Default interval to 1 second + async_interval = 1000 # Default interval to 1 second # save the incoming parms + extra_params async_params = params.to_unsafe_h.merge(options[:extra_params] || {}) @@ -62,8 +59,9 @@ def initiate_wait_for_task(options = {}) async_params[:rx_action] = options[:rx_action] end + session[:async] ||= {} session[:async][:params] = async_params - browser_refresh_task(task_id, async_params, :should_flash => !!options[:flash]) + browser_refresh_task(task_id, async_params, async_interval, :should_flash => !!options[:flash]) end private :initiate_wait_for_task