On Tue, Mar 9, 2010 at 11:27, Nick Zadrozny <[email protected]> wrote:

> Perhaps a patch is in order – I'd love to be able to call something like
> Delayed::Job.current.progress = .5…
>

Easier than I thought. If you decide to go this route, check out
http://github.com/nzadrozny/delayed_job/tree/current_job — it sets the
current job to Delayed::Job.current so you can access it from within the
payload object. From there, you can add a progress column to your
delayed_jobs table which you can then use to poll for progress updates,
since you know the ID of the job when it is created.

The migration…

change_table :delayed_jobs do |t|
  t.integer :progress
end


Inside your job…

Delayed::Job.current.update_attribute :progress, 10


In your app, as a one-off controller action…

def progress
  @job = Delayed::Job.find(params[:id])
  render :text => @job.progress
end


Or, better yet, make a full resource out of your jobs, so you can do other
administratively useful things with them.

def show
  @job = Delayed::Job.find(params[:id])
  respond_to do |format|
    # ...
    format.js { render :json => @job }
  end
end


I'll be sending a pull request to Tobias, we'll see if he thinks my tweak is
worth including in DelayedJob proper.

-- 
Nick Zadrozny

-- 
SD Ruby mailing list
[email protected]
http://groups.google.com/group/sdruby

Reply via email to