Reputation: 896
My application build reports based on data gathered from external APIs what can take a few minutes. Naturally, I do not want to block the worker process. Is it possible to send data gathering to the background and allow user to work with application further? Also it will be good to display the state of the job with SSE or WebSockets.
Upvotes: 0
Views: 1368
Reputation: 311526
Usually you would dispatch a background job to Resque or another background job queue, and have your worker perform jobs from the queue.
That looks like this:
class ReportGenerationJob
# ...
def work
# do expensive operations here
end
end
r = Resque.new
r << ReportGenerationJob.new(...) # Not a blocking operation!
Once a given job is completed, your worker can then signal when it's done in some helpful way (e.g. e-mailing the user that the job is completed; writing a "done!" value to your database; et cetera).
Upvotes: 1