The situation:
I have a Rails 3.1.3 app running which loads a sqlite3 DB and queries it. Standard stuff.
It runs inside an apache with phusion passenger.
Versions are sqlite3 (GEM/1.3.5), ruby 1.9.3-p0, sqlite3 (libs/bin) 3.6.12
The problem:
The sqlite3 file is loaded from a directory that resides outside of the Rails App root and can be updated via a separate (SVN) process
What I want to do is reload the file every five minutes (which is easy).
But how can I reconnect the DB (file) after five minutes in Rails?
What I tried:
Inside my_model.rb:
if time_to_reload
self.connection.reconnect!
self.establish_connection
end
or
if time_to_reload
self.connection.disconnect!
self.connection.reconnect!
end
I tried nearly all permutations of those, no success so far.
I get SQLite3::BusyException: database is locked or prepare called on a closed database
Is there a failsafe way to force a reconnect to the file, closing and reopening all file handles?
Thanks,
Frank
As a sidenote:
1.9.3-p0-perf :006 > MyModel.connection.disconnect!
=> #<SQLite3::Database:0x0000010474f220>
1.9.3-p0-perf :007 > MyModel.connected?
=> true
1.9.3-p0-perf :008 > WAT?
To answer my own question:
works
But it disconnects all databases …