我正在使用 sidekiq 每小时处理数千个作业 - 所有这些作业都 ping 外部 API (Google)。X 千个请求中的一个将返回意外(或空)结果。据我所知,在处理外部 API 时这是不可避免的。
目前,当我遇到这样的响应时,我会引发一个异常,以便重试逻辑在下一次尝试时自动处理它。只有同一个工作多次失败才是真正的错误。异常由 Airbrake 处理。
然而,我的空气制动器被这些并不是真正“问题”的小型中断堵塞了。我希望 Airbrake 仅在同一个工作已经失败 X 次时才收到这些问题的通知。
是否有可能
- 禁用自动空气制动集成,以便我可以使用 sidekiq_retries_exhausted 通过 Airbrake.notify 手动报告错误
- 以某种方式挽救错误,使其不通知 Airbrake 但继续重试?
- 以我没有想到的不同方式做到这一点?
这是我的代码大纲
class GoogleApiWorker
include Sidekiq::Worker
sidekiq_options queue: :critical, backtrace: 5
def perform
# Do stuff interacting with the google API
rescue Exception => e
if is_a_mini_google_outage? e
# How do i make it so this harmless error DOES NOT get reported to Airbrake but still gets retried?
raise e
end
end
def is_a_mini_google_outage? e
# check to see if this is a harmless outage
end
end