【发布时间】:2016-02-06 05:17:11
【问题描述】:
Rails 应用程序有一个调用服务对象的后台作业,如下所示
class ObjectUpdateJob < ActiveJob::Base
queue_as :default
def perform(object_id)
ObjectUpdater.call(object_id)
end
end
class ObjectUpdater
def self.call(*args)
if @object = Object.find( args[:object_id] )
#... update some stuff from external services
else
#... raise an error and prevent the background job from attempting to retry
end
end
end
这可能是一个简单的问题,但我在错误处理方面的经验是有限的,我希望能再考虑一下。
处理这种“记录不存在”情况并确保通知后台作业以便不尝试重试的“Rails 方式”是什么?
【问题讨论】:
-
您可以轻松地使用 rails 方式将异常处理为 edgeguides.rubyonrails.org/active_job_basics.html#exceptions 。但不知道,关于防止工作重试。我没有看到任何文档。
标签: ruby-on-rails error-handling rails-activejob