Only load MySQL2Adapter connection fix is MySQL2 is available.
Useful for Sqlite or Postgres installations.
This commit is contained in:
parent
4b96907e7c
commit
474a42cfbd
1 changed files with 14 additions and 12 deletions
|
@ -1,16 +1,18 @@
|
||||||
module ActiveRecord::ConnectionAdapters
|
if defined?(ActiveRecord::ConnectionAdapters::Mysql2Adapter)
|
||||||
class Mysql2Adapter
|
module ActiveRecord::ConnectionAdapters
|
||||||
alias_method :execute_without_retry, :execute
|
class Mysql2Adapter
|
||||||
|
alias_method :execute_without_retry, :execute
|
||||||
|
|
||||||
def execute(*args)
|
def execute(*args)
|
||||||
execute_without_retry(*args)
|
execute_without_retry(*args)
|
||||||
rescue Mysql2::Error => e
|
rescue Mysql2::Error => e
|
||||||
if e.message =~ /server has gone away/i
|
if e.message =~ /server has gone away/i
|
||||||
warn "Server timed out, retrying"
|
warn "Server timed out, retrying"
|
||||||
reconnect!
|
reconnect!
|
||||||
retry
|
retry
|
||||||
else
|
else
|
||||||
raise e
|
raise e
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue