Created
September 28, 2017 20:52
-
-
Save martinstreicher/98ae3a3b4514856ec4ffd70b07487bc7 to your computer and use it in GitHub Desktop.
Sidekiq Middleware to squelch some errors
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Middleware | |
SquelchedException = Class.new Exception | |
class SidekiqExceptionHandler | |
def call(worker, job, queue) | |
yield | |
rescue Exception => exception | |
notify exception, job, ignore: ignore_exception?(exception) | |
raise SquelchedException | |
end | |
private | |
def ignore_exception?(exception) | |
Bugsnag.configuration.ignore_classes.include?(exception.class.name) | |
end | |
def notify(exception, job, ignore: false) | |
args = job['args'].inject { |result, hash| result.merge hash } | |
ExceptionLoggingService.log(exception, args: args, ignore: ignore) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment