【问题标题】:ActiveJob retry_on callback being ignoredActiveJob retry_on 回调被忽略
【发布时间】:2019-01-23 16:37:18
【问题描述】:

我正在运行 Rails 5.1、ruby 2.5、Sidekiq。 我已经设置了一个简单的用例:

class RetryJobException < Exception

end

class CustomJob < ActiveJob::Base

    retry_on RetryJobException, wait: 3.seconds, attempts: 2 do
        puts "RETRYING"
    end

    def perform(*args)
        raise RetryJobException
    end
end

这里发生的情况是,当我运行此作业并引发 RetryJobException 时,CustomJob 在 30 秒(而不是 3 秒...)后重新运行无限次(而不是 2 次),直到我杀死 Sidekiq 的进程。 "RETRYING" 永远不会在任何地方打印,这表明retry_on 块中的代码永远不会执行。

根据documentation,这应该是一个基本用例,但是,我遇到了这些问题。我做错了什么?

【问题讨论】:

  • 有想过这个吗?

标签: ruby-on-rails rails-activejob


【解决方案1】:

这对我有用:

class RetryJobException < Exception

end

class UnprocessableJob < StandardError; end

class CustomJob < ActiveJob::Base

    retry_on RetryJobException, wait: 3.seconds, attempts: 2 do
        puts "RETRYING"
        before_perform { raise UnprocessableJob }
    end

    discard_on UnprocessableJob

    def perform(*args)
        raise RetryJobException
    end
end

【讨论】:

    猜你喜欢
    • 2013-06-07
    • 2021-01-13
    • 2018-12-03
    • 1970-01-01
    • 2023-03-18
    • 2020-03-23
    • 2021-10-03
    • 1970-01-01
    • 2019-11-24
    相关资源
    最近更新 更多