Monday, February 19, 2007

Rails : Maintaining an Oracle connection (preventing a timeout)

Kubo posted a good note about how to maintain an "active" connection to Oracle from Rails. Add the following code at the end of 'config/environment.rb' as a workaround.

Thread.new(ActiveRecord::Base.connection.raw_connection) do |conn|
  # run a SQL every one hour.
  while true
    sleep(3600)
    conn.exec('select 1 from dual') {}
  end
end

1 comment:

Ohad Asulin said...

Very nice and clean workaround.
I'm going to try and cover this Oracle and Rails specific Issues (one at a time) in this technical blog:
http://oracleonrails.blogspot.com/