views:

28

answers:

2

I need to update a model after delayed_job processes a task on it, e.g:

foo.delay.something

After something is done, I need to update the foo object, what is the best way to achieve this? I was thinking in coding a callback on the Delayed::Backend::ActiveRecord::Job class, but there's should be something cleaner and better to do this.

Thanks in advance.

+1  A: 

I don't understand why you wouldn't do it as part of the job that's already acting on the object.

Joe Martinez
Yes I could `delay` the entire flow, but I'd like to know how to trigger an `after_processed` callback.
jpemberthy
I have a similar situation, but in my case, it works to just queue another job at the end of the first. Also, it's important to note that the jobs that get created are ActiveRecord objects themselves, so if you want to add lifecycle callbacks there, you can do so.
Joe Martinez
Hey thanks, personally, for this specific case, I like more the idea of adding callbacks to the Job instances rather than enqueue a job after another, So, I'm going for the callback on the Job instances :)
jpemberthy
Best of luck!!!
Joe Martinez
A: 

I would just updated it at the end of the #foo method:

def foo
  # do work here
  update_attribute :processed, true
end
bkeepers