ActiveJob retry_on コールバックが無視される
概要
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 回ではなく)、Sidekiq のプロセスを強制終了するまで無制限に (2 回ではなく) 再実行されます。 「RETRYING」はどこにも出力されません。これは、retry_on ブロック内のコードが決して実行されないことを示しています。
ドキュメントによると、これは基本的な使用例であるはずですが、それでもこれらの問題が発生しています。私の何が間違っているのでしょうか?
解決策
これは私にとってはうまくいきました:
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