Indicate to an ajax process that the delayed job has completed
Typically, the best way to do this is to store, in your database, an indication of the job's progress. For instance:
class User def perform_calculation begin self.update_attributes :calculation_status => 'started' do_something_complex self.update_attributes :calculation_status => 'success' rescue Exception => e self.update_attributes :calculation_status => 'error' end endend
So that when you enqueue the job:
User.update_attributes :calculation_status => 'enqueued'User.send_later :perform_calculation
You can query, in your controller, the status of the job:
def check_status @user = User.find(params[:id]) render :json => @user.calculation_statusend
You polling ajax process can then simply call check_status to see how the job is progressing, if it has succeeded or if it has failed.
With this gem you can have progress tracking directly on the Delayed::Job
object itself: https://github.com/GBH/delayed_job_progress
Completed jobs are no longer automatically removed, so you can poll against a job until it comes back with completed
state.
If you are using any JavaScript framework like prototypejs, then in the optional options hash, you usually provide a onComplete and/or onSuccess callback. API Reference