Callback after job execution delayed_job

I need to update the model after it delayed_jobprocesses the task on it, for example:

foo.delay.something

After execution, somethingI need to update the foo object, what is the best way to achieve this? I was thinking about encoding a callback in a class Delayed::Backend::ActiveRecord::Job, but there must be something cleaner and better for this.

+3
source share
3 answers

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

def foo
  # do work here
  update_attribute :processed, true
end
+3
source

I do not understand why you would not do this as part of a task that already acts on an object.

+1
source

, , , ...

, , , . ..:

Delayed::Job.enqueue InstructionRequestJob.new( p1, p2 )

InstructionRequestJob perform
- perform a task on a remote server
- get a response
- case response
  when OK
    update attribute ( as suggested)
  else
    # how many attempts ?
    if too_many_attempts
       update attribute
       destroy the job
    else
       reschedule the job for another attempt
- end
0
source

Source: https://habr.com/ru/post/1754885/


All Articles