As a rule, the best way to do this is to keep an indication of progress in your database. For example:
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 end end
So, when you queue a task:
User.update_attributes :calculation_status => 'enqueued' User.send_later :perform_calculation
You can ask your controller for job status:
def check_status @user = User.find(params[:id]) render :json => @user.calculation_status end
You can then poll the ajax process and simply call check_status to find out how the work is progressing if it succeeds or if it fails.
Pan thomakos
source share