Skip to content

Instantly share code, notes, and snippets.

@loopj
Last active August 29, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save loopj/014b46eb11d826c2870a to your computer and use it in GitHub Desktop.
Save loopj/014b46eb11d826c2870a to your computer and use it in GitHub Desktop.
Send bugsnag error reports asynchronously using resque, sidekiq, etc
# Send Bugsnag error reports asynchronously using Resque
# Add this file to config/initializers/bugsnag_resque.rb
# A simple resque job
class BugsnagResqueJob
@queue = "bugsnag"
def self.perform(*args)
Bugsnag::Notification.deliver_exception_payload_without_resque(*args)
end
end
# Monkey-patch Bugsnag::Notification to use our Resque job
Bugsnag::Notification.class_eval do
class << self
def deliver_exception_payload_with_resque(*args)
Resque.enqueue(BugsnagResqueJob, *args)
end
alias_method :deliver_exception_payload_without_resque, :deliver_exception_payload
alias_method :deliver_exception_payload, :deliver_exception_payload_with_resque
end
end
# Send Bugsnag error reports asynchronously using Sidekiq 3.
# Add this file to config/initializers/bugsnag_sidekiq3.rb
# A simple sidekiq3 worker
class BugsnagSidekiqWorker
include Sidekiq::Worker
def perform(*args)
Bugsnag::Notification.deliver_exception_payload_without_sidekiq(*args)
end
end
# Monkey-patch Bugsnag::Notification to use our Sidekiq worker
Bugsnag::Notification.class_eval do
class << self
def deliver_exception_payload_with_sidekiq(*args)
BugsnagSidekiqWorker.perform_async(*args)
end
alias_method :deliver_exception_payload_without_sidekiq, :deliver_exception_payload
alias_method :deliver_exception_payload, :deliver_exception_payload_with_sidekiq
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment