【问题标题】:Getting `NoMethodError` error when trying to use ActiveJob::Exceptions retry_on method尝试使用 ActiveJob::Exceptions retry_on 方法时出现“NoMethodError”错误
【发布时间】:2019-11-24 09:55:13
【问题描述】:

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

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

  ...
  ...
  ...
end

但是当我这样做时,我得到一个未定义的方法错误:

"未定义的方法`retry_on'...(NoMethodError)"

我的代码与上面的完全一样,只是我正在重试一个不同的错误。我尝试执行此操作的类是继承自 BaseJob 类的作业,该类继承自 ActiveJob::Base。

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

【问题讨论】:

  • 你的 rails 版本是多少?
  • 它是:v4.2.11.1

标签: ruby-on-rails rails-activejob


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2023-03-18
    • 2020-07-31
    • 2015-12-10
    • 2021-06-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-09
    • 2010-10-02
    相关资源
    最近更新 更多