Class: RailsFailover::ActiveRecord::Interceptor
- Inherits:
-
Object
- Object
- RailsFailover::ActiveRecord::Interceptor
- Defined in:
- lib/rails_failover/active_record/middleware.rb
Class Method Summary collapse
- .adapter_errors ⇒ Object
- .handle(request, exception) ⇒ Object
- .resolve_cause(exception) ⇒ Object
- .verify_primary(exception, writing_role) ⇒ Object
Class Method Details
.adapter_errors ⇒ Object
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/rails_failover/active_record/middleware.rb', line 6 def self.adapter_errors @adapter_errors ||= begin if defined?(::PG) [::PG::UnableToSend, ::PG::ConnectionBad] elsif defined?(::Mysql2) [::Mysql2::Error::ConnectionError] end end end |
.handle(request, exception) ⇒ Object
17 18 19 |
# File 'lib/rails_failover/active_record/middleware.rb', line 17 def self.handle(request, exception) verify_primary(exception, request.env[Middleware::WRITING_ROLE_HEADER]) end |
.resolve_cause(exception) ⇒ Object
29 30 31 |
# File 'lib/rails_failover/active_record/middleware.rb', line 29 def self.resolve_cause(exception) exception.cause ? resolve_cause(exception.cause) : exception end |
.verify_primary(exception, writing_role) ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/rails_failover/active_record/middleware.rb', line 21 def self.verify_primary(exception, writing_role) exception = resolve_cause(exception) if adapter_errors.any? { |error| exception.is_a?(error) } Handler.instance.verify_primary(writing_role) end end |