If you just need ActiveRecord and not all of rails, then heres how I
do that.
In pre-daemonize, I have a gems.rb file:
require 'active_record'
In post-daemonize, I have database_setup.rb file:
db_yaml = DaemonKit::Config.load('database')
DaemonKit.logger.info "Setting up ActiveRecord Connection"
ActiveRecord::Base.establish_connection(db_yaml.to_h)
This is loading in a standard database.yml file.
You'll need a lib file for each of your AR models.
class Post < ActiveRecord::Base
end
Then require it inside libexec of where ever you need to use it.
Lastly, I use the AR connection in libexec/daemon_name.rb
loop do
ActiveRecord::Base.connection_pool.with_connection do |conn|
# Do AR work here
end
sleep 60
end
One last note, Sqlite3 database does not work well if you have a Rails
app and a daemon talking to it at the same time. Also configure your
database.yml files on both the rails app and daemon so the pool stays
under whatever your max connections is for your database. If you do
use Sqlite3 for testing, etc in your daemon's database.yml put in the
full path to the database. Daemon-kit currently Dir.chdir to "/" when
it boots.
Ben
> kenneth.kal...@gmail.comhttp://
opensourcery.co.za
> @kennethkalmer