ruby on rails - Indicate to an ajax process that the delayed job has completed -
i have rails 3 app uses delayed_job fetch data (with class method) when user hits page. how can indicate ajax process class method has run (so can stop polling)?
edit:
to clarify, want know when delayed_job has run, not when ajax process has succeeded. want pass delayed_job completed status running ajax process.
typically, best way store, in database, indication of job's progress. 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 end end
so when enqueue job:
user.update_attributes :calculation_status => 'enqueued' user.send_later :perform_calculation
you can query, in controller, status of job:
def check_status @user = user.find(params[:id]) render :json => @user.calculation_status end
you polling ajax process can call check_status see how job progressing, if has succeeded or if has failed.
Comments
Post a Comment