Skip to content

Commit

Permalink
drop session :async :interval
Browse files Browse the repository at this point in the history
passing this as an http parameter, so no need to store in the session
  • Loading branch information
kbrock committed Feb 19, 2025
1 parent 1b58a39 commit f1886c5
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions app/controllers/application_controller/wait_for_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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] || {})
Expand All @@ -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

Expand Down

0 comments on commit f1886c5

Please sign in to comment.