/ Published in: Ruby

Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
# Patch Mysql adapter so that it reconnects after discovering an lost connection error module ActiveRecord::ConnectionAdapters class MysqlAdapter alias :orig_execute :execute def execute(sql,name=nil) orig_execute(sql,name) rescue ActiveRecord::StatementInvalid => exception if LOST_CONNECTION_ERROR_MESSAGES.any? { |msg| exception.message. =~ /#{msg}/ } reconnect! retry else raise end end end end
Comments
