Load Ruby on Rails models without loading the entire framework

Posted by epochwolf on Stack Overflow See other posts from Stack Overflow or by epochwolf
Published on 2009-11-18T17:26:59Z Indexed on 2010/04/09 3:03 UTC
Read the original article Hit count: 403

I'm looking to create a custom daemon that will run various database tasks such as delaying mailings and user notifications (each notice is a separate row in the notifications table). I don't want to use script/runner or rake to do these tasks because it is possible that some of the tasks only require the create of one or two database rows or thousands of rows depending on the task. I don't want the overhead of launching a ruby process or loading the entire rails framework for each operation. I plan to keep this daemon in memory full time.

To create this daemon I would like to use my models from my ruby on rails application. I have a number of rails plugins such as acts_as_tree and AASM that I will need loaded if I where to use the models. Some of the plugins I need to load are custom hacks on ActiveRecord::Base that I've created. (I am willing to accept removing or recoding some of the plugins if they need components from other parts of rails.)

My questions are

  • Is this a good idea?
  • And - Is this possible to do in a way that doesn't have me manually including each file in my models and plugins?

If not a good idea

  • What is a good alternative?

(I am not apposed to doing writing my own SQL queries but I would have to add database constraints and a separate user for the daemon to prevent any stupid accidents. Given my lack of familiarity with configuring a database, I would like to use active record as a crutch.)

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about ruby