[Backgroundrb-devel] Production RAILS_ENV / DB Selection

skaar skaar at waste.org
Tue Nov 21 15:41:23 EST 2006


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
----------------------------------------------------------------------


More information about the Backgroundrb-devel mailing list