Class: Postman::ConnectionMissing

Inherits:
ActiveRecord::StatementInvalid
  • Object
show all
Defined in:
lib/postman/message.rb

Overview

An artificial subclass of ActiveRecord::StatementInvalid that just detects issues with the database connection

Constant Summary collapse

DATABASE_CONNECTION_MESSAGES =

Database connection messages indicated temporary issues connecting to the database We handle them separately to ensure we can recover from network issues.

[
  /Mysql2::Error: closed MySQL connection:/, # 2013,
  /Mysql2::Error: MySQL server has gone away/, # 2006
  /Mysql2::Error: Can't connect to local MySQL server through socket/, # , 2002, 2001, 2003, 2004, 2005,
  /Mysql2::Error: MySQL client is not connected/
].freeze

Class Method Summary collapse

Class Method Details

.===(other) ⇒ Object


18
19
20
# File 'lib/postman/message.rb', line 18

def self.===(other)
  other.is_a?(ActiveRecord::StatementInvalid) && database_connection_error?(other)
end

.database_connection_error?(exception) ⇒ Boolean

Returns:

  • (Boolean)

22
23
24
# File 'lib/postman/message.rb', line 22

def self.database_connection_error?(exception)
  DATABASE_CONNECTION_MESSAGES.any? { |regex| regex.match?(exception.message) }
end