Custom Environments/Framework Exclusion

Hey all,

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
Rails
framework for each worker, which can incur quite a bit of memory
overhead as
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
don’t
need. Basically all you need is ActiveRecord and ActiveSupport, which
would
allow me to exclude ActionController, ActionView, ActionMailer, and
ActionWebService.

However, I quickly found out that you can’t set config.framework from
the
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
ENV[‘RAILS_ENV’] ==
‘background’

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,
but
I don’t like the sound of that either…

Thanks!

Matt

Thermal Creative
http://blog.thermalcreative.com