Skip to content

Instantly share code, notes, and snippets.

View ihassin's full-sized avatar
🏠
Working from home

Itamar Hassin ihassin

🏠
Working from home
View GitHub Profile
@ihassin
ihassin / Reconnect
Created June 3, 2012 14:51
Reconnect to a lost database connection using an exception block trick (ruby, rails, mysql, activerecord)
def my_task
while(true) do
begin
database_access_here
rescue Exception => ex
begin
ActiveRecord::Base.connection.reconnect!
rescue
sleep 10
retry # will retry the reconnect