Skip to content

Commit 6b17d66

Browse files
committed
wait_for_task passes interval as a param (instead of the session)
1 parent def63ef commit 6b17d66

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

app/controllers/application_controller/wait_for_task.rb

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,24 @@ def wait_for_task
1212
raise Forbidden, _('Invalid input for "wait_for_task".') unless params[:task_id]
1313

1414
session[:async] ||= {}
15-
session[:async][:interval] ||= 1000 # Default interval to 1 second
15+
async_interval = params[:async_interval] || 1000 # Default interval to 1 second
1616
session[:async][:params] ||= {}
1717

1818
if MiqTask.find(params[:task_id].to_i).state != "Finished" # Task not done --> retry
19-
browser_refresh_task(params[:task_id])
19+
browser_refresh_task(params[:task_id], async_interval)
2020
else # Task done
2121
session[:async][:params].each { |k, v| @_params[k] = v } # Merge in the original params and
2222
send(session.fetch_path(:async, :params, :action)) # call the orig. method
2323
end
2424
end
2525

26-
def browser_refresh_task(task_id, should_flash: false)
27-
session[:async][:interval] += 250 if session[:async][:interval] < 5000 # Slowly move up to 5 second retries
26+
def browser_refresh_task(task_id, async_interval, should_flash: false)
27+
async_interval = 1000 if async_interval.to_i < 1000 # if it is not an integer, assign to 1 second
28+
async_interval += 250 if async_interval < 5000 # Slowly move up to 5 second retries
2829
render :update do |page|
2930
page << javascript_prologue
30-
ajax_call = remote_function(:url => {:action => 'wait_for_task', :task_id => task_id})
31-
page << "setTimeout(\"#{ajax_call}\", #{session[:async][:interval]});"
31+
ajax_call = remote_function(:url => {:action => 'wait_for_task', :task_id => task_id, :async_interval => async_interval})
32+
page << "setTimeout(\"#{ajax_call}\", #{async_interval});"
3233
page.replace("flash_msg_div", :partial => "layouts/flash_msg") if should_flash
3334
page << "miqScrollTop();" if @flash_array.present?
3435
end
@@ -44,7 +45,7 @@ def browser_refresh_task(task_id, should_flash: false)
4445
def initiate_wait_for_task(options = {})
4546
task_id = options[:task_id]
4647
session[:async] ||= {}
47-
session[:async][:interval] ||= 1000 # Default interval to 1 second
48+
async_interval = 1000 # Default interval to 1 second
4849
session[:async][:params] ||= {}
4950

5051
# save the incoming parms + extra_params
@@ -61,7 +62,7 @@ def initiate_wait_for_task(options = {})
6162
session[:async][:params][:rx_action] = options[:rx_action]
6263
end
6364

64-
browser_refresh_task(task_id, :should_flash => !!options[:flash])
65+
browser_refresh_task(task_id, async_interval, :should_flash => !!options[:flash])
6566
end
6667
private :initiate_wait_for_task
6768

0 commit comments

Comments
 (0)