Commit 474a42cfbd939f644eb5d900e447dae48142508a
1 parent
4b96907e
Exists in
master
and in
4 other branches
Only load MySQL2Adapter connection fix is MySQL2 is available.
Useful for Sqlite or Postgres installations.
Showing
1 changed file
with
14 additions
and
12 deletions
Show diff stats
config/initializers/connection_fix.rb
| 1 | -module ActiveRecord::ConnectionAdapters | ||
| 2 | - class Mysql2Adapter | ||
| 3 | - alias_method :execute_without_retry, :execute | 1 | +if defined?(ActiveRecord::ConnectionAdapters::Mysql2Adapter) |
| 2 | + module ActiveRecord::ConnectionAdapters | ||
| 3 | + class Mysql2Adapter | ||
| 4 | + alias_method :execute_without_retry, :execute | ||
| 4 | 5 | ||
| 5 | - def execute(*args) | ||
| 6 | - execute_without_retry(*args) | ||
| 7 | - rescue Mysql2::Error => e | ||
| 8 | - if e.message =~ /server has gone away/i | ||
| 9 | - warn "Server timed out, retrying" | ||
| 10 | - reconnect! | ||
| 11 | - retry | ||
| 12 | - else | ||
| 13 | - raise e | 6 | + def execute(*args) |
| 7 | + execute_without_retry(*args) | ||
| 8 | + rescue Mysql2::Error => e | ||
| 9 | + if e.message =~ /server has gone away/i | ||
| 10 | + warn "Server timed out, retrying" | ||
| 11 | + reconnect! | ||
| 12 | + retry | ||
| 13 | + else | ||
| 14 | + raise e | ||
| 15 | + end | ||
| 14 | end | 16 | end |
| 15 | end | 17 | end |
| 16 | end | 18 | end |