diff --git a/config/initializers/connection_fix.rb b/config/initializers/connection_fix.rb index d15b0c20..c29f6b11 100644 --- a/config/initializers/connection_fix.rb +++ b/config/initializers/connection_fix.rb @@ -1,16 +1,18 @@ -module ActiveRecord::ConnectionAdapters - class Mysql2Adapter - alias_method :execute_without_retry, :execute +if defined?(ActiveRecord::ConnectionAdapters::Mysql2Adapter) + module ActiveRecord::ConnectionAdapters + class Mysql2Adapter + alias_method :execute_without_retry, :execute - def execute(*args) - execute_without_retry(*args) - rescue Mysql2::Error => e - if e.message =~ /server has gone away/i - warn "Server timed out, retrying" - reconnect! - retry - else - raise e + def execute(*args) + execute_without_retry(*args) + rescue Mysql2::Error => e + if e.message =~ /server has gone away/i + warn "Server timed out, retrying" + reconnect! + retry + else + raise e + end end end end