I have a web application where I need to perform a process that takes a while to complete (Usually 1 minute).
I'll try to explain it briefly: In my app I have an algorithm that assigns foreign keys to a set of objects based on a bunch of parameters (mainly dates). When a user presses the designated button inside my application a controller method is executed. Inside that method I make a call to a method in the model where all the logic is handled and the keys are being assigned. As mentioned before, the whole process takes about a minute to complete.
So my question is: What is the best way to run this process in the background in Rails 5? I obviously don't want to force my users to wait an entire minute before they can navigate around the application and I also don't want the application to time out while the browser is waiting for a response from the server. So what's the best way to handle this? Do I need a framework that can make the request asynchronously? If so, which one? (I would prefer if it doesn't require too many dependencies and if I can keep using ActiveRecord).
I haven't really worked too much with ActionCable or AJAX, but if they can get the job done in any way, then I would be thrilled to know how.
Ideally I should be able to send a notification to the user, within the app, once the process is done
view.html.erb:
# Button the user presses to execute the algorithm
<%= link_to 'execute algorithm', algorithm_path(@variable), :method => :put %>
my_controller.rb:
def button_method
Object.execute_algorithm(@variable)
redirect_to :back
end
Object.rb:
def self.execute_algorithm(variable)
# Logic
end