Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default delivery method #346

Merged
merged 2 commits into from
Feb 10, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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