Created
June 27, 2013 13:25
-
-
Save MrAlexLau/5876372 to your computer and use it in GitHub Desktop.
How to ignore Sidekiq exceptions in Airbrake for a rails project.
This file contains 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
#config/initializers/airbrake.rb | |
Airbrake.configure do |config| | |
config.api_key = 'mySecretKeyGoesHere' | |
config.ignore << "CustomSidekiqException" #do not report our custom exceptions to Airbrake | |
end |
This file contains 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
#app/models/custom_sidekiq_exception.rb | |
class CustomSidekiqException < StandardError | |
#just make sure this inherits from standard error | |
#you can add whatever attributes you want to this class, but don't need to | |
end |
This file contains 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
#config/initializers/sidekiq.rb | |
module WrappedErrors | |
class Sidekiq | |
#call a worker per usual | |
#only this time wrap in a begin/rescue block for errors | |
#re-raise the error using our custom error type | |
def call(worker, msg, queue) | |
begin | |
yield | |
rescue => ex | |
raise CustomSidekiqException, ex.message | |
end | |
end | |
end | |
end | |
Sidekiq.configure_server do |config| | |
config.redis = { :url => 'redis://localhost:6379/0', :namespace => 'sidekiq_namespace' } | |
config.server_middleware do |chain| | |
#add the WrappedErrors module to the sidekiq chain of events | |
chain.add ::WrappedErrors::Sidekiq | |
end | |
end | |
Sidekiq.configure_client do |config| | |
config.redis = { :url => 'redis://localhost:6379/0', :namespace => 'sidekiq_namespace' } | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment