[Backgroundrb-devel] Setting environment

Steve Sloan steve at finagle.org
Sun Oct 15 15:27:54 EDT 2006

Chris T wrote:
> Not sure this is known behaviour but it seems that if want to set the 
> environment to, for example, test, and you want to use Active Record you 
> have to both explicitly set the RAILS_ENV and the BackgrounDRb environment.

I ran into essentially the same problem (needing to run BRB in the test
environment so AR would use the right DB).  My "solution" was to add entries
in backgroundrb.yml for environment, log_file and pid_file to allow for
multiple instances of BRB to run simultaneously in different environments.  My
config now looks like:

environment: <%= ENV['RAILS_ENV'] %>
port: <%= 22222 + ['production', 'development', 'test'].index(ENV['RAILS_ENV']) %>
log_file: <%= "log/brb-#{ENV['RAILS_ENV']}.log" %>
pid_file: <%= "log/brb-#{ENV['RAILS_ENV']}.pid" %>

Obviously, I had to hack BRB to use these settings, modify the start/stop
scripts to take an --env argument, and add Rake tasks to (re)start the test
instance.  Add that restart task as a preqreq of 'test', and the BRB test
instance will restart (and reload) before each test run.

If interested, I can provide diffs ...

-- Steve

More information about the Backgroundrb-devel mailing list