Skip to content

Instantly share code, notes, and snippets.

@thbar
Created December 29, 2008 16:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thbar/41305 to your computer and use it in GitHub Desktop.
Save thbar/41305 to your computer and use it in GitHub Desktop.
Patch to use ActiveRecord 2.2.2 outside Rails
# patch to handle connection pooling outside of rails: http://www.williambharding.com/blog/rants/rails-22-connection-pools-mongrel-handlers-bloodbath/
# call ActiveRecord::Base.connection_handler.clear_connection! at the end of your requests (or as soon as you don't need AR anymore).
module ActiveRecord
module ConnectionAdapters
class ConnectionPool
def release_connection(conn_id = nil)
conn_id ||= current_connection_id
conn = @reserved_connections.delete(conn_id)
checkin conn if conn
end
end
class ConnectionHandler
def clear_connection!
@connection_pools.each_value {|pool| pool.release_connection(Thread.current.object_id) }
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment