Skip to content

Commit

Permalink
Default delivery method (#346)
Browse files Browse the repository at this point in the history
* use the configured delivery_method here similar to sidekiq

* integrations should not overwrite the delivery method if set by the developer
  • Loading branch information
martin308 committed Feb 10, 2017
1 parent b9ae19b commit 987fc06
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 6 deletions.
26 changes: 24 additions & 2 deletions lib/bugsnag/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ class Configuration
attr_accessor :proxy_password
attr_accessor :timeout
attr_accessor :hostname
attr_accessor :delivery_method
attr_writer :ignore_classes

THREAD_LOCAL_NAME = "bugsnag_req_data"
Expand Down Expand Up @@ -77,7 +76,6 @@ def initialize
self.ignore_user_agents = Set.new(DEFAULT_IGNORE_USER_AGENTS)
self.endpoint = DEFAULT_ENDPOINT
self.hostname = default_hostname
self.delivery_method = DEFAULT_DELIVERY_METHOD
self.timeout = 15
self.vendor_paths = [%r{vendor/}]
self.notify_release_stages = nil
Expand All @@ -96,6 +94,30 @@ def initialize
self.middleware.use Bugsnag::Middleware::Callbacks
end

##
# Gets the delivery_method that Bugsnag will use to communicate with the
# notification endpoint.
#
def delivery_method
@delivery_method || @default_delivery_method || DEFAULT_DELIVERY_METHOD
end

##
# Sets the delivery_method that Bugsnag will use to communicate with the
# notification endpoint.
#
def delivery_method=(delivery_method)
@delivery_method = delivery_method
end

##
# Used to set a new default delivery method that will be used if one is not
# set with #delivery_method.
#
def default_delivery_method=(delivery_method)
@default_delivery_method = delivery_method
end

# Accept both String and Class instances as an ignored class
def ignore_classes
@mutex.synchronize { @ignore_classes.map! { |klass| klass.is_a?(Class) ? klass.name : klass } }
Expand Down
4 changes: 2 additions & 2 deletions lib/bugsnag/resque.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def self.add_failure_backend
end

def save
Bugsnag.auto_notify(exception, {:context => "#{payload['class']}@#{queue}", :payload => payload, :delivery_method => :synchronous})
Bugsnag.auto_notify(exception, {:context => "#{payload['class']}@#{queue}", :payload => payload})
end
end
end
Expand All @@ -39,5 +39,5 @@ def save

Resque.before_first_fork do
Bugsnag.configuration.app_type = "resque"
Bugsnag.configuration.delivery_method = :synchronous
Bugsnag.configuration.default_delivery_method = :synchronous
end
2 changes: 1 addition & 1 deletion lib/bugsnag/shoryuken.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module Bugsnag
class Shoryuken
def initialize
Bugsnag.configuration.app_type = "shoryuken"
Bugsnag.configuration.delivery_method = :synchronous
Bugsnag.configuration.default_delivery_method = :synchronous
end

def call(_, queue, _, body)
Expand Down
2 changes: 1 addition & 1 deletion lib/bugsnag/sidekiq.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class Sidekiq
def initialize
Bugsnag.configuration.internal_middleware.use(Bugsnag::Middleware::Sidekiq)
Bugsnag.configuration.app_type = "sidekiq"
Bugsnag.configuration.delivery_method = :synchronous
Bugsnag.configuration.default_delivery_method = :synchronous
end

def call(worker, msg, queue)
Expand Down
26 changes: 26 additions & 0 deletions spec/configuration_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# encoding: utf-8
require 'spec_helper'

describe Bugsnag::Configuration do
describe "delivery_method" do
it "should have the default delivery method" do
expect(subject.delivery_method).to eq(Bugsnag::Configuration::DEFAULT_DELIVERY_METHOD)
end

it "should have the defined delivery_method" do
subject.delivery_method = :test
expect(subject.delivery_method).to eq(:test)
end

it "should allow a new default delivery_method to be set" do
subject.default_delivery_method = :test
expect(subject.delivery_method).to eq(:test)
end

it "should allow the delivery_method to be set over a default" do
subject.default_delivery_method = :test
subject.delivery_method = :wow
expect(subject.delivery_method).to eq(:wow)
end
end
end

0 comments on commit 987fc06

Please sign in to comment.