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

#wip catch connection pool errors #302

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
3 changes: 2 additions & 1 deletion lib/exception_notification/rails.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ class Engine < ::Rails::Engine
config.exception_notification = ExceptionNotifier
config.exception_notification.logger = Rails.logger

config.app_middleware.use ExceptionNotification::Rack
# config.app_middleware.use ExceptionNotification::Rack
config.app_middleware.insert_before ActiveRecord::ConnectionAdapters::ConnectionManagement, ExceptionNotification::Rack
end
end
6 changes: 3 additions & 3 deletions test/dummy/config/database.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
development:
adapter: sqlite3
database: db/development.sqlite3
pool: 5
pool: 1
timeout: 5000

# Warning: The database defined as "test" will be erased and
Expand All @@ -12,11 +12,11 @@ development:
test:
adapter: sqlite3
database: db/test.sqlite3
pool: 5
pool: 1
timeout: 5000

production:
adapter: sqlite3
database: db/production.sqlite3
pool: 5
pool: 1
timeout: 5000
42 changes: 42 additions & 0 deletions test/dummy/config/initializers/exception_notification.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
require 'exception_notification/rails'

ExceptionNotification.configure do |config|
# Ignore additional exception types.
# ActiveRecord::RecordNotFound, AbstractController::ActionNotFound and ActionController::RoutingError are already added.
# config.ignored_exceptions += %w{ActionView::TemplateError CustomError}

# Adds a condition to decide when an exception must be ignored or not.
# The ignore_if method can be invoked multiple times to add extra conditions.
# config.ignore_if do |exception, options|
# not Rails.env.production?
# end

# Notifiers =================================================================

# Email notifier sends notifications by email.
config.add_notifier :email, {
:email_prefix => "[ERROR] ",
:sender_address => %{"Notifier" <[email protected]>},
:exception_recipients => %w{[email protected]}
}

# Campfire notifier sends notifications to your Campfire room. Requires 'tinder' gem.
# config.add_notifier :campfire, {
# :subdomain => 'my_subdomain',
# :token => 'my_token',
# :room_name => 'my_room'
# }

# HipChat notifier sends notifications to your HipChat room. Requires 'hipchat' gem.
# config.add_notifier :hipchat, {
# :api_token => 'my_token',
# :room_name => 'my_room'
# }

# Webhook notifier sends notifications over HTTP protocol. Requires 'httparty' gem.
# config.add_notifier :webhook, {
# :url => 'http://example.com:5555/hubot/path',
# :http_method => :post
# }

end
13 changes: 13 additions & 0 deletions test/exception_notifier_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,19 @@ class ExceptionNotifierTest < ActiveSupport::TestCase
assert_equal ExceptionNotifier.notifiers, [:email]
end

test "can catch database connection pool problems" do
begin
a = b = nil
a = ActiveRecord::Base.connection_pool.checkout
b = ActiveRecord::Base.connection_pool.checkout
ActiveRecord::Base.connection_pool.checkout

ensure
ActiveRecord::Base.connection_pool.checkin a rescue nil
ActiveRecord::Base.connection_pool.checkin b rescue nil
end
end

test "should ignore exception if satisfies conditional ignore" do
env = "production"
ExceptionNotifier.ignore_if do |exception, options|
Expand Down