Hey all, I''m having some issues moving a project that incorporates Backgroundrb onto a staging server... For some reason (surely of my own doing), my RailsBase workers are insisting on using trying to access my development DB instead of my "production" DB. When I try to load a model object from within a worker, I get the following: 20061120-21:54:28 (26296) #<DRb::DRbUnknown:0x40691130> 20061120-21:54:28 (26296) /var/www/gorchie/releases/20061120100506/config/../vendor/rails/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb:387:in `real_connect'' /var/www/gorchie/releases/20061120100506/config/../vendor/rails/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb:387:in `connect'' /var/www/gorchie/releases/20061120100506/config/../vendor/rails/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb:151:in `initialize'' /var/www/gorchie/releases/20061120100506/config/../vendor/rails/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb:82:in `mysql_connection'' /var/www/gorchie/releases/20061120100506/config/../vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb:252:in `connection_without_query_cache='' /var/www/gorchie/releases/20061120100506/config/../vendor/rails/activerecord/lib/active_record/query_cache.rb:54:in `connection='' /var/www/gorchie/releases/20061120100506/config/../vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb:220:in `retrieve_connection'' /var/www/gorchie/releases/20061120100506/config/../vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb:78:in `connection'' /var/www/gorchie/releases/20061120100506/config/../vendor/rails/activerecord/lib/active_record/base.rb:760:in `columns'' /var/www/gorchie/releases/20061120100506/config/../vendor/rails/activerecord/lib/active_record/base.rb:768:in `columns_hash'' /var/www/gorchie/releases/20061120100506/config/../vendor/rails/activerecord/lib/active_record/base.rb:1020:in `find_one'' /var/www/gorchie/releases/20061120100506/config/../vendor/rails/activerecord/lib/active_record/base.rb:1011:in `find_from_ids'' /var/www/gorchie/releases/20061120100506/config/../vendor/rails/activerecord/lib/active_record/base.rb:416:in `find'' /var/www/gorchie/releases/20061120100506/lib/workers/upload_process_worker.rb:14:in `do_work'' /var/www/gorchie/releases/20061120100506/vendor/plugins/backgroundrb/server/lib/backgroundrb/worker.rb:49:in `work_thread'' /var/www/gorchie/releases/20061120100506/vendor/plugins/backgroundrb/server/lib/backgroundrb/worker.rb:49:in `work_thread'' /usr/local/lib/ruby/1.8/drb/drb.rb:1552:in `perform_without_block'' /usr/local/lib/ruby/1.8/drb/drb.rb:1512:in `perform'' /usr/local/lib/ruby/1.8/drb/drb.rb:1586:in `main_loop'' /usr/local/lib/ruby/1.8/drb/drb.rb:1582:in `main_loop'' /usr/local/lib/ruby/1.8/drb/drb.rb:1578:in `main_loop'' /usr/local/lib/ruby/1.8/drb/drb.rb:1427:in `run'' /usr/local/lib/ruby/1.8/drb/drb.rb:1424:in `run'' /usr/local/lib/ruby/1.8/drb/drb.rb:1344:in `initialize'' /usr/local/lib/ruby/1.8/drb/drb.rb:1624:in `start_service'' /usr/local/lib/ruby/gems/1.8/gems/slave-1.0.0/lib/slave.rb:205:in `initialize'' /usr/local/lib/ruby/gems/1.8/gems/slave-1.0.0/lib/slave.rb:200:in `initialize'' /var/www/gorchie/releases/20061120100506/vendor/plugins/backgroundrb/server/lib/backgroundrb/middleman.rb:169:in `new_worker'' /var/www/gorchie/releases/20061120100506/vendor/plugins/backgroundrb/server/lib/backgroundrb/thread_pool.rb:36:in `dispatch'' /var/www/gorchie/releases/20061120100506/vendor/plugins/backgroundrb/server/lib/backgroundrb/thread_pool.rb:22:in `dispatch'' /var/www/gorchie/releases/20061120100506/vendor/plugins/backgroundrb/server/lib/backgroundrb/middleman.rb:159:in `new_worker'' /usr/local/lib/ruby/1.8/drb/drb.rb:1552:in `perform_without_block'' /usr/local/lib/ruby/1.8/drb/drb.rb:1512:in `perform'' /usr/local/lib/ruby/1.8/drb/drb.rb:1586:in `main_loop'' /usr/local/lib/ruby/1.8/drb/drb.rb:1582:in `main_loop'' /usr/local/lib/ruby/1.8/drb/drb.rb:1578:in `main_loop'' /usr/local/lib/ruby/1.8/drb/drb.rb:1427:in `run'' /usr/local/lib/ruby/1.8/drb/drb.rb:1424:in `run'' /usr/local/lib/ruby/1.8/drb/drb.rb:1344:in `initialize'' /usr/local/lib/ruby/1.8/drb/drb.rb:1624:in `start_service'' /var/www/gorchie/releases/20061120100506/vendor/plugins/backgroundrb/server/lib/backgroundrb_server.rb:215:in `run'' /usr/local/lib/ruby/gems/1.8/gems/daemons-1.0.3/lib/daemons/application.rb:186:in `start_proc'' /usr/local/lib/ruby/gems/1.8/gems/daemons-1.0.3/lib/daemons/daemonize.rb:208:in `call_as_daemon'' /usr/local/lib/ruby/gems/1.8/gems/daemons-1.0.3/lib/daemons/application.rb:190:in `start_proc'' /usr/local/lib/ruby/gems/1.8/gems/daemons-1.0.3/lib/daemons/application.rb:226:in `start'' /usr/local/lib/ruby/gems/1.8/gems/daemons-1.0.3/lib/daemons/controller.rb:69:in `run'' /usr/local/lib/ruby/gems/1.8/gems/daemons-1.0.3/lib/daemons.rb:179:in `run_proc'' /usr/local/lib/ruby/gems/1.8/gems/daemons-1.0.3/lib/daemons/cmdline.rb:94:in `catch_exceptions'' /usr/local/lib/ruby/gems/1.8/gems/daemons-1.0.3/lib/daemons.rb:178:in `run_proc'' /var/www/gorchie/releases/20061120100506/vendor/plugins/backgroundrb/server/lib/backgroundrb_server.rb:204:in `run'' script/backgroundrb:29 I then went into the backgroundrb console and basically ran the same code as appears in the RailsBase.initialize() method to init the DB based on the current ENV[''RAILS_ENV''] (which is set to "production" in my backgroundrb config file). The bit that calls establish_connection on ActiveRecord::Base works fine, and seems to connect to the production DB, because I''m able to run manual queries with execute() against it and get results. However, when I include environment.rb to load Rails, and then subsequently try to run queries against my models, I get the access denied error that indicates that it''s trying to access my dev DB instead of my production DB. So, it seems that somehow Rails is starting in development mode even though I can confirm that ENV[''RAILS_ENV''] == "production". However, if I check the value of RAILS_ENV while within the backgroundrb console, it is set to "development". So, for some reason ENV[''RAILS_ENV''] does not have the same value as RAILS_ENV. So, I''m stumped. It all works fine locally, but I''m running in dev mode locally so this issue wouldn''t surface. Any help or insight would be greatly appreciated. Thanks, Matt White -- Thermal Creative http://blog.thermalcreative.com -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/backgroundrb-devel/attachments/20061121/27544fd5/attachment.html
More info... I''ve managed to duplicate the issue on my local machine, and it seems that since RailsBase is parsed before Config loads info (including my :rails_env), it boots Rails in it''s default mode of "development". ( initializer.rb, line 5: RAILS_ENV = (ENV[''RAILS_ENV''] || ''development'').dup unless defined?(RAILS_ENV)) I could see it on the console by switching my production config with my dev config in my database.yml. So, if I try to access my "development" DB, it will throw errors, but "production" should work since it''s actually my dev db. When I manually call new_worker on the console, I get authentication errors thrown that indicate that it''s trying to access my development DB. The fix is to call reload! to force it to reload the worker classes. When the workers get reloaded, ENV[''RAILS_ENV''] is picked up by boot.rb, and it starts targeting the right DB. So, if I call new_worker after calling reload! it all works fine. So...that said, anyone have any ideas about how to fix this? I obviously can''t call reload on the MiddleMan every time I start a new worker to make sure that it''s got the right RAILS_ENV... Thanks! Matt On 11/21/06, Matt White <stockliasteroid at gmail.com> wrote:> > Hey all, > > I''m having some issues moving a project that incorporates Backgroundrb > onto a staging server... For some reason (surely of my own doing), my > RailsBase workers are insisting on using trying to access my development DB > instead of my "production" DB. > > When I try to load a model object from within a worker, I get the > following: > > 20061120-21:54:28 (26296) #<DRb::DRbUnknown:0x40691130> > 20061120-21:54:28 (26296) > /var/www/gorchie/releases/20061120100506/config/../vendor/rails/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb:387:in > `real_connect'' > /var/www/gorchie/releases/20061120100506/config/../vendor/rails/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb:387:in > `connect'' > /var/www/gorchie/releases/20061120100506/config/../vendor/rails/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb:151:in > `initialize'' > /var/www/gorchie/releases/20061120100506/config/../vendor/rails/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb:82:in > `mysql_connection'' > /var/www/gorchie/releases/20061120100506/config/../vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb:252:in > `connection_without_query_cache='' > /var/www/gorchie/releases/20061120100506/config/../vendor/rails/activerecord/lib/active_record/query_cache.rb:54:in > `connection='' > /var/www/gorchie/releases/20061120100506/config/../vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb:220:in > `retrieve_connection'' > /var/www/gorchie/releases/20061120100506/config/../vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb:78:in > `connection'' > /var/www/gorchie/releases/20061120100506/config/../vendor/rails/activerecord/lib/active_record/base.rb:760:in > `columns'' > /var/www/gorchie/releases/20061120100506/config/../vendor/rails/activerecord/lib/active_record/base.rb:768:in > `columns_hash'' > /var/www/gorchie/releases/20061120100506/config/../vendor/rails/activerecord/lib/active_record/base.rb:1020:in > `find_one'' > /var/www/gorchie/releases/20061120100506/config/../vendor/rails/activerecord/lib/active_record/base.rb:1011:in > `find_from_ids'' > /var/www/gorchie/releases/20061120100506/config/../vendor/rails/activerecord/lib/active_record/base.rb:416:in > `find'' > /var/www/gorchie/releases/20061120100506/lib/workers/upload_process_worker.rb:14:in > `do_work'' > /var/www/gorchie/releases/20061120100506/vendor/plugins/backgroundrb/server/lib/backgroundrb/worker.rb:49:in > `work_thread'' > /var/www/gorchie/releases/20061120100506/vendor/plugins/backgroundrb/server/lib/backgroundrb/worker.rb:49:in > `work_thread'' > /usr/local/lib/ruby/1.8/drb/drb.rb:1552:in `perform_without_block'' > /usr/local/lib/ruby/1.8/drb/drb.rb:1512:in `perform'' > /usr/local/lib/ruby/1.8/drb/drb.rb:1586:in `main_loop'' > /usr/local/lib/ruby/1.8/drb/drb.rb:1582:in `main_loop'' > /usr/local/lib/ruby/1.8/drb/drb.rb:1578:in `main_loop'' > /usr/local/lib/ruby/1.8/drb/drb.rb:1427:in `run'' > /usr/local/lib/ruby/1.8/drb/drb.rb:1424:in `run'' > /usr/local/lib/ruby/1.8/drb/drb.rb:1344:in `initialize'' > /usr/local/lib/ruby/1.8/drb/drb.rb:1624:in `start_service'' > /usr/local/lib/ruby/gems/1.8/gems/slave-1.0.0 /lib/slave.rb:205:in > `initialize'' > /usr/local/lib/ruby/gems/1.8/gems/slave-1.0.0/lib/slave.rb:200:in > `initialize'' > /var/www/gorchie/releases/20061120100506/vendor/plugins/backgroundrb/server/lib/backgroundrb/middleman.rb:169:in > `new_worker'' > /var/www/gorchie/releases/20061120100506/vendor/plugins/backgroundrb/server/lib/backgroundrb/thread_pool.rb:36:in > `dispatch'' > /var/www/gorchie/releases/20061120100506/vendor/plugins/backgroundrb/server/lib/backgroundrb/thread_pool.rb:22:in > `dispatch'' > /var/www/gorchie/releases/20061120100506/vendor/plugins/backgroundrb/server/lib/backgroundrb/middleman.rb:159:in > `new_worker'' > /usr/local/lib/ruby/1.8/drb/drb.rb:1552:in `perform_without_block'' > /usr/local/lib/ruby/1.8/drb/drb.rb:1512:in `perform'' > /usr/local/lib/ruby/1.8/drb/drb.rb:1586:in `main_loop'' > /usr/local/lib/ruby/1.8/drb/drb.rb:1582:in `main_loop'' > /usr/local/lib/ruby/1.8/drb/drb.rb:1578:in `main_loop'' > /usr/local/lib/ruby/1.8/drb/drb.rb:1427:in `run'' > /usr/local/lib/ruby/1.8/drb/drb.rb:1424:in `run'' > /usr/local/lib/ruby/1.8/drb/drb.rb:1344:in `initialize'' > /usr/local/lib/ruby/1.8/drb/drb.rb:1624:in `start_service'' > /var/www/gorchie/releases/20061120100506/vendor/plugins/backgroundrb/server/lib/backgroundrb_server.rb:215:in > `run'' > /usr/local/lib/ruby/gems/1.8/gems/daemons-1.0.3/lib/daemons/application.rb:186:in > `start_proc'' > /usr/local/lib/ruby/gems/1.8/gems/daemons-1.0.3/lib/daemons/daemonize.rb:208:in > `call_as_daemon'' > /usr/local/lib/ruby/gems/1.8/gems/daemons- 1.0.3/lib/daemons/application.rb:190:in > `start_proc'' > /usr/local/lib/ruby/gems/1.8/gems/daemons-1.0.3/lib/daemons/application.rb:226:in > `start'' > /usr/local/lib/ruby/gems/1.8/gems/daemons-1.0.3/lib/daemons/controller.rb:69:in > `run'' > /usr/local/lib/ruby/gems/1.8/gems/daemons-1.0.3/lib/daemons.rb:179:in > `run_proc'' > /usr/local/lib/ruby/gems/1.8/gems/daemons-1.0.3/lib/daemons/cmdline.rb:94:in > `catch_exceptions'' > /usr/local/lib/ruby/gems/1.8/gems/daemons- 1.0.3/lib/daemons.rb:178:in > `run_proc'' > /var/www/gorchie/releases/20061120100506/vendor/plugins/backgroundrb/server/lib/backgroundrb_server.rb:204:in > `run'' > script/backgroundrb:29 > > I then went into the backgroundrb console and basically ran the same code > as appears in the RailsBase.initialize() method to init the DB based on > the current ENV[''RAILS_ENV''] (which is set to "production" in my > backgroundrb config file). The bit that calls establish_connection on > ActiveRecord::Base works fine, and seems to connect to the production DB, > because I''m able to run manual queries with execute() against it and get > results. > > However, when I include environment.rb to load Rails, and then > subsequently try to run queries against my models, I get the access denied > error that indicates that it''s trying to access my dev DB instead of my > production DB. So, it seems that somehow Rails is starting in development > mode even though I can confirm that ENV[''RAILS_ENV''] == "production". > However, if I check the value of RAILS_ENV while within the backgroundrb > console, it is set to "development". So, for some reason ENV[''RAILS_ENV''] > does not have the same value as RAILS_ENV. > > So, I''m stumped. It all works fine locally, but I''m running in dev mode > locally so this issue wouldn''t surface. > > Any help or insight would be greatly appreciated. > > Thanks, > > Matt White > -- > Thermal Creative > http://blog.thermalcreative.com-- Thermal Creative http://blog.thermalcreative.com -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/backgroundrb-devel/attachments/20061122/530c6283/attachment.html
I''ll try to look at this. Could you give it a try and move: 5: require BACKGROUNDRB_ROOT + ''/config/boot.rb'' inside initialize in RailsBase - I''ll see if we can do something about load order. thanks /skaar * Matt White (stockliasteroid at gmail.com) [061121 14:26]:> More info... > > I''ve managed to duplicate the issue on my local machine, and it seems that > since RailsBase is parsed before Config loads info (including my > :rails_env), it boots Rails in it''s default mode of "development". ( > initializer.rb, line 5: RAILS_ENV = (ENV[''RAILS_ENV''] || > ''development'').dup unless defined?(RAILS_ENV)) > > I could see it on the console by switching my production config with my > dev config in my database.yml. So, if I try to access my "development" DB, > it will throw errors, but "production" should work since it''s actually my > dev db. > > When I manually call new_worker on the console, I get authentication > errors thrown that indicate that it''s trying to access my development DB. > The fix is to call reload! to force it to reload the worker classes. When > the workers get reloaded, ENV[''RAILS_ENV''] is picked up by boot.rb, and it > starts targeting the right DB. So, if I call new_worker after calling > reload! it all works fine. > > So...that said, anyone have any ideas about how to fix this? I obviously > can''t call reload on the MiddleMan every time I start a new worker to make > sure that it''s got the right RAILS_ENV... > > Thanks! > > Matt > > On 11/21/06, Matt White <[1]stockliasteroid at gmail.com > wrote: > > Hey all, > > I''m having some issues moving a project that incorporates Backgroundrb > onto a staging server... For some reason (surely of my own doing), my > RailsBase workers are insisting on using trying to access my development > DB instead of my "production" DB. > > When I try to load a model object from within a worker, I get the > following: > > 20061120-21:54:28 (26296) #<DRb::DRbUnknown:0x40691130> > 20061120-21:54:28 (26296) > /var/www/gorchie/releases/20061120100506/config/../vendor/rails/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb:387:in > `real_connect'' > /var/www/gorchie/releases/20061120100506/config/../vendor/rails/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb:387:in > `connect'' > /var/www/gorchie/releases/20061120100506/config/../vendor/rails/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb:151:in > `initialize'' > /var/www/gorchie/releases/20061120100506/config/../vendor/rails/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb:82:in > `mysql_connection'' > /var/www/gorchie/releases/20061120100506/config/../vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb:252:in > `connection_without_query_cache='' > /var/www/gorchie/releases/20061120100506/config/../vendor/rails/activerecord/lib/active_record/query_cache.rb:54:in > `connection='' > /var/www/gorchie/releases/20061120100506/config/../vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb:220:in > `retrieve_connection'' > /var/www/gorchie/releases/20061120100506/config/../vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb:78:in > `connection'' > /var/www/gorchie/releases/20061120100506/config/../vendor/rails/activerecord/lib/active_record/base.rb:760:in > `columns'' > /var/www/gorchie/releases/20061120100506/config/../vendor/rails/activerecord/lib/active_record/base.rb:768:in > `columns_hash'' > /var/www/gorchie/releases/20061120100506/config/../vendor/rails/activerecord/lib/active_record/base.rb:1020:in > `find_one'' > /var/www/gorchie/releases/20061120100506/config/../vendor/rails/activerecord/lib/active_record/base.rb:1011:in > `find_from_ids'' > /var/www/gorchie/releases/20061120100506/config/../vendor/rails/activerecord/lib/active_record/base.rb:416:in > `find'' > /var/www/gorchie/releases/20061120100506/lib/workers/upload_process_worker.rb:14:in > `do_work'' > /var/www/gorchie/releases/20061120100506/vendor/plugins/backgroundrb/server/lib/backgroundrb/worker.rb:49:in > `work_thread'' > /var/www/gorchie/releases/20061120100506/vendor/plugins/backgroundrb/server/lib/backgroundrb/worker.rb:49:in > `work_thread'' > /usr/local/lib/ruby/1.8/drb/drb.rb:1552:in `perform_without_block'' > /usr/local/lib/ruby/1.8/drb/drb.rb:1512:in `perform'' > /usr/local/lib/ruby/1.8/drb/drb.rb:1586:in `main_loop'' > /usr/local/lib/ruby/1.8/drb/drb.rb:1582:in `main_loop'' > /usr/local/lib/ruby/1.8/drb/drb.rb:1578:in `main_loop'' > /usr/local/lib/ruby/1.8/drb/drb.rb:1427:in `run'' > /usr/local/lib/ruby/1.8/drb/drb.rb:1424:in `run'' > /usr/local/lib/ruby/1.8/drb/drb.rb:1344:in `initialize'' > /usr/local/lib/ruby/1.8/drb/drb.rb:1624:in `start_service'' > /usr/local/lib/ruby/gems/1.8/gems/slave-1.0.0 /lib/slave.rb:205:in > `initialize'' > /usr/local/lib/ruby/gems/1.8/gems/slave-1.0.0/lib/slave.rb:200:in > `initialize'' > /var/www/gorchie/releases/20061120100506/vendor/plugins/backgroundrb/server/lib/backgroundrb/middleman.rb:169:in > `new_worker'' > /var/www/gorchie/releases/20061120100506/vendor/plugins/backgroundrb/server/lib/backgroundrb/thread_pool.rb:36:in > `dispatch'' > /var/www/gorchie/releases/20061120100506/vendor/plugins/backgroundrb/server/lib/backgroundrb/thread_pool.rb:22:in > `dispatch'' > /var/www/gorchie/releases/20061120100506/vendor/plugins/backgroundrb/server/lib/backgroundrb/middleman.rb:159:in > `new_worker'' > /usr/local/lib/ruby/1.8/drb/drb.rb:1552:in `perform_without_block'' > /usr/local/lib/ruby/1.8/drb/drb.rb:1512:in `perform'' > /usr/local/lib/ruby/1.8/drb/drb.rb:1586:in `main_loop'' > /usr/local/lib/ruby/1.8/drb/drb.rb:1582:in `main_loop'' > /usr/local/lib/ruby/1.8/drb/drb.rb:1578:in `main_loop'' > /usr/local/lib/ruby/1.8/drb/drb.rb:1427:in `run'' > /usr/local/lib/ruby/1.8/drb/drb.rb:1424:in `run'' > /usr/local/lib/ruby/1.8/drb/drb.rb:1344:in `initialize'' > /usr/local/lib/ruby/1.8/drb/drb.rb:1624:in `start_service'' > /var/www/gorchie/releases/20061120100506/vendor/plugins/backgroundrb/server/lib/backgroundrb_server.rb:215:in > `run'' > /usr/local/lib/ruby/gems/1.8/gems/daemons-1.0.3/lib/daemons/application.rb:186:in > `start_proc'' > /usr/local/lib/ruby/gems/1.8/gems/daemons-1.0.3/lib/daemons/daemonize.rb:208:in > `call_as_daemon'' > /usr/local/lib/ruby/gems/1.8/gems/daemons- > 1.0.3/lib/daemons/application.rb:190:in `start_proc'' > /usr/local/lib/ruby/gems/1.8/gems/daemons-1.0.3/lib/daemons/application.rb:226:in > `start'' > /usr/local/lib/ruby/gems/1.8/gems/daemons-1.0.3/lib/daemons/controller.rb:69:in > `run'' > /usr/local/lib/ruby/gems/1.8/gems/daemons-1.0.3/lib/daemons.rb:179:in > `run_proc'' > /usr/local/lib/ruby/gems/1.8/gems/daemons-1.0.3/lib/daemons/cmdline.rb:94:in > `catch_exceptions'' > /usr/local/lib/ruby/gems/1.8/gems/daemons- 1.0.3/lib/daemons.rb:178:in > `run_proc'' > /var/www/gorchie/releases/20061120100506/vendor/plugins/backgroundrb/server/lib/backgroundrb_server.rb:204:in > `run'' > script/backgroundrb:29 > > I then went into the backgroundrb console and basically ran the same > code as appears in the RailsBase.initialize() method to init the DB > based on the current ENV[''RAILS_ENV''] (which is set to "production" in > my backgroundrb config file). The bit that calls establish_connection on > ActiveRecord::Base works fine, and seems to connect to the production > DB, because I''m able to run manual queries with execute() against it and > get results. > > However, when I include environment.rb to load Rails, and then > subsequently try to run queries against my models, I get the access > denied error that indicates that it''s trying to access my dev DB instead > of my production DB. So, it seems that somehow Rails is starting in > development mode even though I can confirm that ENV[''RAILS_ENV''] => "production". However, if I check the value of RAILS_ENV while within > the backgroundrb console, it is set to "development". So, for some > reason ENV[''RAILS_ENV''] does not have the same value as RAILS_ENV. > > So, I''m stumped. It all works fine locally, but I''m running in dev mode > locally so this issue wouldn''t surface. > > Any help or insight would be greatly appreciated. > > Thanks, > > Matt White > -- > Thermal Creative > [2]http://blog.thermalcreative.com > > -- > Thermal Creative > [3]http://blog.thermalcreative.com > > References > > Visible links > 1. mailto:stockliasteroid at gmail.com > 2. http://blog.thermalcreative.com/ > 3. http://blog.thermalcreative.com/> _______________________________________________ > Backgroundrb-devel mailing list > Backgroundrb-devel at rubyforge.org > http://rubyforge.org/mailman/listinfo/backgroundrb-devel-- ---------------------------------------------------------------------- |\|\ where in the | s_u_b_s_t_r_u_c_t_i_o_n | | >=========== W.A.S.T.E. | genarratologies |/|/ (_) is the wisdom | skaar at waste.org ----------------------------------------------------------------------
And one more... Sorry for spamming the list, but I keep answering my own questions :) The problem seems to come from the fact that backgroundrb_server requires worker, which then in turn requires worker_rails, all before the config file is parsed, thus making it too early for Rails to load with the appropriate RAILS_ENV from the config file. So, I moved: unless BACKGROUNDRB_STANDALONE require ''backgroundrb/worker_rails'' end from the end of worker.rb to near the end of BackgrounDRb::Server#config so that Worker::RailsBase is only loaded after the appropriate ENV[''RAILS_ENV''] has been set. I''ve confirmed that this seems to fix the issue, and I''m able to hit the right DB now from the console without having to force a reload. So, Ezra or Skaar, do you have any comments? I''ve been kinda shooting in the dark, and I want to make sure I''m not way off base :) Thanks, Matt On 11/22/06, Matt White <stockliasteroid at gmail.com> wrote:> > More info... > > I''ve managed to duplicate the issue on my local machine, and it seems that > since RailsBase is parsed before Config loads info (including my > :rails_env), it boots Rails in it''s default mode of "development". ( > initializer.rb, line 5: RAILS_ENV = (ENV[''RAILS_ENV''] || > ''development'').dup unless defined?(RAILS_ENV)) > > I could see it on the console by switching my production config with my > dev config in my database.yml. So, if I try to access my "development" DB, > it will throw errors, but "production" should work since it''s actually my > dev db. > > When I manually call new_worker on the console, I get authentication > errors thrown that indicate that it''s trying to access my development DB. > The fix is to call reload! to force it to reload the worker classes. When > the workers get reloaded, ENV[''RAILS_ENV''] is picked up by boot.rb, and it > starts targeting the right DB. So, if I call new_worker after calling > reload! it all works fine. > > So...that said, anyone have any ideas about how to fix this? I obviously > can''t call reload on the MiddleMan every time I start a new worker to make > sure that it''s got the right RAILS_ENV... > > Thanks! > > Matt > > On 11/21/06, Matt White <stockliasteroid at gmail.com > wrote: > > > > Hey all, > > > > I''m having some issues moving a project that incorporates Backgroundrb > > onto a staging server... For some reason (surely of my own doing), my > > RailsBase workers are insisting on using trying to access my development DB > > instead of my "production" DB. > > > > When I try to load a model object from within a worker, I get the > > following: > > > > 20061120-21:54:28 (26296) #<DRb::DRbUnknown:0x40691130> > > 20061120-21:54:28 (26296) > > /var/www/gorchie/releases/20061120100506/config/../vendor/rails/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb:387:in > > `real_connect'' > > /var/www/gorchie/releases/20061120100506/config/../vendor/rails/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb:387:in > > `connect'' > > /var/www/gorchie/releases/20061120100506/config/../vendor/rails/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb:151:in > > `initialize'' > > /var/www/gorchie/releases/20061120100506/config/../vendor/rails/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb:82:in > > `mysql_connection'' > > /var/www/gorchie/releases/20061120100506/config/../vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb:252:in > > `connection_without_query_cache='' > > /var/www/gorchie/releases/20061120100506/config/../vendor/rails/activerecord/lib/active_record/query_cache.rb:54:in > > `connection='' > > /var/www/gorchie/releases/20061120100506/config/../vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb:220:in > > `retrieve_connection'' > > /var/www/gorchie/releases/20061120100506/config/../vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb:78:in > > `connection'' > > /var/www/gorchie/releases/20061120100506/config/../vendor/rails/activerecord/lib/active_record/base.rb:760:in > > `columns'' > > /var/www/gorchie/releases/20061120100506/config/../vendor/rails/activerecord/lib/active_record/base.rb:768:in > > `columns_hash'' > > /var/www/gorchie/releases/20061120100506/config/../vendor/rails/activerecord/lib/active_record/base.rb:1020:in > > `find_one'' > > /var/www/gorchie/releases/20061120100506/config/../vendor/rails/activerecord/lib/active_record/base.rb:1011:in > > `find_from_ids'' > > /var/www/gorchie/releases/20061120100506/config/../vendor/rails/activerecord/lib/active_record/base.rb:416:in > > `find'' > > /var/www/gorchie/releases/20061120100506/lib/workers/upload_process_worker.rb:14:in > > `do_work'' > > /var/www/gorchie/releases/20061120100506/vendor/plugins/backgroundrb/server/lib/backgroundrb/worker.rb:49:in > > `work_thread'' > > /var/www/gorchie/releases/20061120100506/vendor/plugins/backgroundrb/server/lib/backgroundrb/worker.rb:49:in > > `work_thread'' > > /usr/local/lib/ruby/1.8/drb/drb.rb:1552:in `perform_without_block'' > > /usr/local/lib/ruby/1.8/drb/drb.rb:1512:in `perform'' > > /usr/local/lib/ruby/1.8/drb/drb.rb:1586:in `main_loop'' > > /usr/local/lib/ruby/1.8/drb/drb.rb:1582:in `main_loop'' > > /usr/local/lib/ruby/1.8/drb/drb.rb:1578:in `main_loop'' > > /usr/local/lib/ruby/1.8/drb/drb.rb:1427:in `run'' > > /usr/local/lib/ruby/1.8/drb/drb.rb:1424:in `run'' > > /usr/local/lib/ruby/1.8/drb/drb.rb:1344:in `initialize'' > > /usr/local/lib/ruby/1.8/drb/drb.rb:1624:in `start_service'' > > /usr/local/lib/ruby/gems/1.8/gems/slave-1.0.0 /lib/slave.rb:205:in > > `initialize'' > > /usr/local/lib/ruby/gems/1.8/gems/slave-1.0.0/lib/slave.rb:200:in > > `initialize'' > > /var/www/gorchie/releases/20061120100506/vendor/plugins/backgroundrb/server/lib/backgroundrb/middleman.rb:169:in > > `new_worker'' > > /var/www/gorchie/releases/20061120100506/vendor/plugins/backgroundrb/server/lib/backgroundrb/thread_pool.rb:36:in > > `dispatch'' > > /var/www/gorchie/releases/20061120100506/vendor/plugins/backgroundrb/server/lib/backgroundrb/thread_pool.rb:22:in > > `dispatch'' > > /var/www/gorchie/releases/20061120100506/vendor/plugins/backgroundrb/server/lib/backgroundrb/middleman.rb:159:in > > `new_worker'' > > /usr/local/lib/ruby/1.8/drb/drb.rb:1552:in `perform_without_block'' > > /usr/local/lib/ruby/1.8/drb/drb.rb:1512:in `perform'' > > /usr/local/lib/ruby/1.8/drb/drb.rb:1586:in `main_loop'' > > /usr/local/lib/ruby/1.8/drb/drb.rb:1582:in `main_loop'' > > /usr/local/lib/ruby/1.8/drb/drb.rb:1578:in `main_loop'' > > /usr/local/lib/ruby/1.8/drb/drb.rb:1427:in `run'' > > /usr/local/lib/ruby/1.8/drb/drb.rb:1424:in `run'' > > /usr/local/lib/ruby/1.8/drb/drb.rb:1344:in `initialize'' > > /usr/local/lib/ruby/1.8/drb/drb.rb:1624:in `start_service'' > > /var/www/gorchie/releases/20061120100506/vendor/plugins/backgroundrb/server/lib/backgroundrb_server.rb:215:in > > `run'' > > /usr/local/lib/ruby/gems/1.8/gems/daemons-1.0.3/lib/daemons/application.rb:186:in > > `start_proc'' > > /usr/local/lib/ruby/gems/1.8/gems/daemons-1.0.3/lib/daemons/daemonize.rb:208:in > > `call_as_daemon'' > > /usr/local/lib/ruby/gems/1.8/gems/daemons- 1.0.3/lib/daemons/application.rb:190:in > > `start_proc'' > > /usr/local/lib/ruby/gems/1.8/gems/daemons-1.0.3/lib/daemons/application.rb:226:in > > `start'' > > /usr/local/lib/ruby/gems/1.8/gems/daemons-1.0.3/lib/daemons/controller.rb:69:in > > `run'' > > /usr/local/lib/ruby/gems/1.8/gems/daemons-1.0.3/lib/daemons.rb:179:in > > `run_proc'' > > /usr/local/lib/ruby/gems/1.8/gems/daemons-1.0.3/lib/daemons/cmdline.rb:94:in > > `catch_exceptions'' > > /usr/local/lib/ruby/gems/1.8/gems/daemons- 1.0.3/lib/daemons.rb:178:in > > `run_proc'' > > /var/www/gorchie/releases/20061120100506/vendor/plugins/backgroundrb/server/lib/backgroundrb_server.rb:204:in > > `run'' > > script/backgroundrb:29 > > > > I then went into the backgroundrb console and basically ran the same > > code as appears in the RailsBase.initialize() method to init the DB > > based on the current ENV[''RAILS_ENV''] (which is set to "production" in my > > backgroundrb config file). The bit that calls establish_connection on > > ActiveRecord::Base works fine, and seems to connect to the production DB, > > because I''m able to run manual queries with execute() against it and get > > results. > > > > However, when I include environment.rb to load Rails, and then > > subsequently try to run queries against my models, I get the access denied > > error that indicates that it''s trying to access my dev DB instead of my > > production DB. So, it seems that somehow Rails is starting in development > > mode even though I can confirm that ENV[''RAILS_ENV''] == "production". > > However, if I check the value of RAILS_ENV while within the backgroundrb > > console, it is set to "development". So, for some reason ENV[''RAILS_ENV''] > > does not have the same value as RAILS_ENV. > > > > So, I''m stumped. It all works fine locally, but I''m running in dev mode > > locally so this issue wouldn''t surface. > > > > Any help or insight would be greatly appreciated. > > > > Thanks, > > > > Matt White > > -- > > Thermal Creative > > http://blog.thermalcreative.com > > > > > -- > Thermal Creative > http://blog.thermalcreative.com >-- Thermal Creative http://blog.thermalcreative.com -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/backgroundrb-devel/attachments/20061122/350049d3/attachment-0001.html
* Matt White (stockliasteroid at gmail.com) [061121 15:08]:> And one more... Sorry for spamming the list, but I keep answering my own > questions :) > > The problem seems to come from the fact that backgroundrb_server requires > worker, which then in turn requires worker_rails, all before the config > file is parsed, thus making it too early for Rails to load with the > appropriate RAILS_ENV from the config file. So, I moved: > > unless BACKGROUNDRB_STANDALONE > require ''backgroundrb/worker_rails'' > endok, thanks for going through the trouble. In trunk r159 worker_rails is loaded in BackgrounDRb::Server#setup. I''d be great next time if you can log the issue, so we can keep track of things like this. thanks again /skaar -- ---------------------------------------------------------------------- |\|\ where in the | s_u_b_s_t_r_u_c_t_i_o_n | | >=========== W.A.S.T.E. | genarratologies |/|/ (_) is the wisdom | skaar at waste.org ----------------------------------------------------------------------