[英]Callback after delayed_job process job
我需要在delayed_job
处理任务后更新模型,例如:
foo.delay.something
完成something
后,我需要更新foo对象,实现这个目标的最佳方法是什么? 我正在考虑编写一个关于Delayed::Backend::ActiveRecord::Job
类的回调,但应该有更清洁,更好的事情。
我会在#foo方法的最后更新它:
def foo
# do work here
update_attribute :processed, true
end
我不明白为什么你不会把它作为已经作用于对象的工作的一部分。
按建议更新记录很好,但它只是解决方案的一部分......
如果我想要更多地控制失败时该做什么,回调会有所帮助..即:
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.