Class: RailsFailover::ActiveRecord::Interceptor

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_failover/active_record/middleware.rb

Class Method Summary collapse

Class Method Details

.adapter_errorsObject



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