Skip to content

Instantly share code, notes, and snippets.

@takai
Created December 12, 2011 21:49
Show Gist options
  • Save takai/1469270 to your computer and use it in GitHub Desktop.
Save takai/1469270 to your computer and use it in GitHub Desktop.
development:
adapter: mysql2
encoding: utf8
reconnect: false
database: mysql_read_timeout_development
pool: 5
username: root
password:
socket: /tmp/mysql.sock
read_timeout: 1
without_timeout:
adapter: mysql2
encoding: utf8
reconnect: false
database: mysql_read_timeout_development
pool: 5
username: root
password:
socket: /tmp/mysql.sock
class Employee < ActiveRecord::Base
def self.sleep
find_by_sql 'select sleep(2) as name'
end
end
class EmployeesController < ApplicationController
def show
begin
Employee.sleep
rescue ActiveRecord::StatementInvalid
ActiveRecord::Base.establish_connection('without_timeout')
Employee.sleep
end
@employee = Employee.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.json { render :json => @employee }
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment