I have a really strange problem with Backgroundrb. On one of my staging servers, it is not recognizing the RAILS_ENV variable for some reason. I have tried everything I could, that is:
a) stopping and starting from the command line by issuing the following command
RAILS_ENV=staging script/backgroundrb stop|start
b) script/backgroundrb stop|start -e staging
c) from the Capistrano script, here are the relevant snippets:
namespace :backgroundrb do desc "Start backgroundrb service" task :start, :roles => :app do run "RAILS_ENV=#{rails_env} nohup #{current_path}/script/backgroundrb start 2>&1 1>/dev/null" end
desc "Stop backgroundrb service" task :stop, :roles => :app do # echo at end makes the return code always 0 run "test -f #{current_path}/log/backgroundrb.pid && #{current_path}/script/backgroundrb stop; echo" end
desc "Restart backgroundrb service" task :restart, :roles => :app do stop start end
end
When I look at the log, it is clear to me that it is picking up the development environment since the backgroundrb workers are looking for the development database. See the following snippet from the log:
Started reminders processing at: 2008-10-28 21:40:01 Unknown database 'isabont_dev' /var/www/apps/isabont/releases/20081028150434/vendor/rails/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb:505:in `real_connect' /var/www/apps/isabont/releases/20081028150434/vendor/rails/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb:505:in `connect' /var/www/apps/isabont/releases/20081028150434/vendor/rails/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb:183:in `initialize' /var/www/apps/isabont/releases/20081028150434/vendor/rails/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb:88:in `new' /var/www/apps/isabont/releases/20081028150434/vendor/rails/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb:88:in `mysql_connection' /var/www/apps/isabont/releases/20081028150434/vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb:292:in `send' /var/www/apps/isabont/releases/20081028150434/vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb:292:in `connection=' /var/www/apps/isabont/releases/20081028150434/vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb:260:in `retrieve_connection' /var/www/apps/isabont/releases/20081028150434/vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb:78:in `connection' /var/www/apps/isabont/releases/20081028150434/vendor/rails/activerecord/lib/active_record/base.rb:2693:in `quoted_table_name' /var/www/apps/isabont/releases/20081028150434/vendor/rails/activerecord/lib/active_record/base.rb:1469:in `construct_finder_sql' /var/www/apps/isabont/releases/20081028150434/vendor/rails/activerecord/lib/active_record/base.rb:1341:in `find_every' /var/www/apps/isabont/releases/20081028150434/vendor/rails/activerecord/lib/active_record/base.rb:536:in `find' /var/www/apps/isabont/current/app/models/reminder.rb:84:in `find_delinquent' 12286,1 99%
That 'isabont_dev' is my development database. Why is it failing to pick up the right environment all of sudden? If it had picked up staging then my database would be isabont_staging since that is how my database.yml is configured. What is bad is that this used to work fine on the same server. That is; I have deployed on this server using the Capistrano deploy.rb many times before. Exactly the same script works fine on yet another server in another staging environment (for UK).
Seems like Backgroundrb is stuck on not recognizing the RAILS_ENV no matter how it is passed to it and defaults to development since it is trying to query the dev database.
Anyone has experienced this kind of inconsistent behavior in Backgroundrb?
Thanks in advance for your time and apologies for the long post.
Bharat