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

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -