繁体   English   中英

retry_on 会在 discard_on 之前先被执行吗?

[英]does retry_on get excuted first before discard_on?

语境:

我有一份工作可以捕获这些配置的一些错误

class CheckBankStatusJob < BaseJob
  discard_on(ConnectionErrors::Error) do
   Logger.new(STDOUT).warn("Connection Error!")
  end

  retry_on(
   BankError::NoResponseData,
   StandardError,
   wait: 5.seconds,
  )
end

ConnectionErrors继承自StandardError

BankError::NoResponseData继承自StandardError

我想测试 rspec 中的discard_on事件

it "logs down when RemoteErrors::Error" do
 allow_any_instance_of(described_class).to receive(:perform).and_raise(ConnectionErrors::Error)
 expect_any_instance_of(Logger).to receive(:warn).with("Connection Error!")
 described_class.perform_now
end

它永远不会 go 到discard_on块,而是转到retry_on块。

错误

Failure/Error:
expected: 1 time with arguments: xxx
received: 0 times

retry_on是否首先执行? 或者是因为ConnectionErrors继承自StandardError

提前致谢

我认为您需要将“perform”替换为“perform_now”以引发 ConnectionErrors::Error

allow_any_instance_of(described_class).to receive(:perform_now).and_raise(ConnectionErrors::Error)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM