尝试使用 ActiveJob::Exceptions retry_on 方法时出现“NoMethodError”错误

Getting `NoMethodError` error when trying to use ActiveJob::Exceptions retry_on method

出于某种原因,我在尝试使用 ActiveJob::Exceptions retry_on 方法时遇到错误。文档显示了这种用法:

class RemoteServiceJob < ActiveJob::Base
  retry_on CustomAppException # defaults to 3s wait, 5 attempts

  ...
  ...
  ...
end

但是当我这样做时,出现未定义方法错误:

"undefined method `retry_on'...(NoMethodError)"

我的代码与上面的代码完全一样,除了我正在重试一个不同的错误。我尝试执行此操作的 class 是一项继承自 BaseJob classt 的工作,该工作继承自 ActiveJob::Base.

有谁知道我为什么会得到这个结果?如果我扩展 ActiveJob::Base 为什么不定义方法?

因为 retry_on 已添加到 Rails 5.1。它在 5.1 之前不可用。如您所说,您使用的是 Rails 4,因此异常是合法的。