I’m using BackgrounDRb to do some offline tasks, and the creators of
BackgrounDRb have created a worker class that allows you access to your
ActiveRecord model objects. The problem is that to do so it boots the
framework for each worker, which can incur quite a bit of memory
well as longer startup time.
So, I thought that the solution would be to create another Rails
environment, call it “background”, and exclude all of the frameworks I
need. Basically all you need is ActiveRecord and ActiveSupport, which
allow me to exclude ActionController, ActionView, ActionMailer, and
However, I quickly found out that you can’t set config.framework from
environment-specific configuration files (production.rb, development.rb,
etc), because Rails::Initializer calls load_frameworks before it calls
load_environment, which means that by the time you get chance to set the
frameworks from your specific environment it’s too late.
So, the best solution I came up with is:
config.frameworks -= [ :action_view, :action_mailer ] if
within the main environment.rb.
This seems kind of hacky, though. Any better ideas?
Also, is it possible to exclude ActionController as well? When I try to
eliminate it, I get errors because ActiveSupport tries to extend
ActionController on load. I suppose I could trap and ignore the errors,
I don’t like the sound of that either…