Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

delayed_job forces database access on assets:precompile #405

Closed
luismreis opened this Issue Jun 22, 2012 · 3 comments

Comments

Projects
None yet
4 participants

When using delayed_job (directly or through delayed_job_active_record), doing a "rake assets:precompile" forces a database access.

This happens on ruby 1.9.3 (mri), rails 3.2.6.

It's caused by the extension of the ActiveRecord::Base class on lib/delayed/psych_ext.rb on lines 2-8. This code indirectly adds a callback to the app / rake initialization (active_record.set_reloader_hooks) forcing the connection to the database.

Steps to reproduce:

  1. Create a new rails app. ("rails new test-app -d postgresql")
    1.1) run "cd test-app"

  2. run "rake assets:precompile"
    2.1) This will run without problems

  3. Add "gem 'delayed_job'" to Gemfile, next to "gem 'pg'"

  4. run "bundle"

  5. run "rake assets:precompile --trace"
    5.1) This will break with an exception trying to connect to an non-existing database.

  6. run "bundle open delayed_job"

  7. edit "lib/delayed/psych_ext.rb" and comment lines 2 through 8

  8. run "rake assets:precompile --trace"
    8.1) This will run without problems

Example stack trace:

could not translate host name "127.0.0.1z" to address: nodename nor servname provided, or not known
$HOME/.rvm/gems/ruby-1.9.3-p194@my-project/gems/activerecord-3.2.6/lib/active_record/connection_adapters/postgresql_adapter.rb:1206:in `initialize'
$HOME/.rvm/gems/ruby-1.9.3-p194@my-project/gems/activerecord-3.2.6/lib/active_record/connection_adapters/postgresql_adapter.rb:1206:in `new'
$HOME/.rvm/gems/ruby-1.9.3-p194@my-project/gems/activerecord-3.2.6/lib/active_record/connection_adapters/postgresql_adapter.rb:1206:in `connect'
$HOME/.rvm/gems/ruby-1.9.3-p194@my-project/gems/activerecord-3.2.6/lib/active_record/connection_adapters/postgresql_adapter.rb:329:in `initialize'
$HOME/.rvm/gems/ruby-1.9.3-p194@my-project/gems/activerecord-3.2.6/lib/active_record/connection_adapters/postgresql_adapter.rb:28:in `new'
$HOME/.rvm/gems/ruby-1.9.3-p194@my-project/gems/activerecord-3.2.6/lib/active_record/connection_adapters/postgresql_adapter.rb:28:in `postgresql_connection'
$HOME/.rvm/gems/ruby-1.9.3-p194@my-project/gems/activerecord-3.2.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:309:in `new_connection'
$HOME/.rvm/gems/ruby-1.9.3-p194@my-project/gems/activerecord-3.2.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:319:in `checkout_new_connection'
$HOME/.rvm/gems/ruby-1.9.3-p194@my-project/gems/activerecord-3.2.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:241:in `block (2 levels) in checkout'
$HOME/.rvm/gems/ruby-1.9.3-p194@my-project/gems/activerecord-3.2.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:236:in `loop'
$HOME/.rvm/gems/ruby-1.9.3-p194@my-project/gems/activerecord-3.2.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:236:in `block in checkout'
$HOME/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
$HOME/.rvm/gems/ruby-1.9.3-p194@my-project/gems/activerecord-3.2.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:233:in `checkout'
$HOME/.rvm/gems/ruby-1.9.3-p194@my-project/gems/activerecord-3.2.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:96:in `block in connection'
$HOME/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
$HOME/.rvm/gems/ruby-1.9.3-p194@my-project/gems/activerecord-3.2.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:95:in `connection'
$HOME/.rvm/gems/ruby-1.9.3-p194@my-project/gems/activerecord-3.2.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:404:in `retrieve_connection'
$HOME/.rvm/gems/ruby-1.9.3-p194@my-project/gems/activerecord-3.2.6/lib/active_record/connection_adapters/abstract/connection_specification.rb:168:in `retrieve_connection'
$HOME/.rvm/gems/ruby-1.9.3-p194@my-project/gems/activerecord-3.2.6/lib/active_record/connection_adapters/abstract/connection_specification.rb:142:in `connection'
$HOME/.rvm/gems/ruby-1.9.3-p194@my-project/gems/activerecord-3.2.6/lib/active_record/model_schema.rb:308:in `clear_cache!'
$HOME/.rvm/gems/ruby-1.9.3-p194@my-project/gems/activerecord-3.2.6/lib/active_record/railtie.rb:97:in `block (2 levels) in <class:Railtie>'
$HOME/.rvm/gems/ruby-1.9.3-p194@my-project/gems/activesupport-3.2.6/lib/active_support/callbacks.rb:422:in `_run__4463707566002008710__prepare__3321247384314589629__callbacks'
$HOME/.rvm/gems/ruby-1.9.3-p194@my-project/gems/activesupport-3.2.6/lib/active_support/callbacks.rb:409:in `__run_callback'
$HOME/.rvm/gems/ruby-1.9.3-p194@my-project/gems/activesupport-3.2.6/lib/active_support/callbacks.rb:385:in `_run_prepare_callbacks'
$HOME/.rvm/gems/ruby-1.9.3-p194@my-project/gems/activesupport-3.2.6/lib/active_support/callbacks.rb:81:in `run_callbacks'
$HOME/.rvm/gems/ruby-1.9.3-p194@my-project/gems/actionpack-3.2.6/lib/action_dispatch/middleware/reloader.rb:75:in `prepare!'
$HOME/.rvm/gems/ruby-1.9.3-p194@my-project/gems/actionpack-3.2.6/lib/action_dispatch/middleware/reloader.rb:48:in `prepare!'
$HOME/.rvm/gems/ruby-1.9.3-p194@my-project/gems/railties-3.2.6/lib/rails/application/finisher.rb:50:in `block in <module:Finisher>'
$HOME/.rvm/gems/ruby-1.9.3-p194@my-project/gems/railties-3.2.6/lib/rails/initializable.rb:30:in `instance_exec'
$HOME/.rvm/gems/ruby-1.9.3-p194@my-project/gems/railties-3.2.6/lib/rails/initializable.rb:30:in `run'
$HOME/.rvm/gems/ruby-1.9.3-p194@my-project/gems/railties-3.2.6/lib/rails/initializable.rb:56:in `block in run_initializers'
$HOME/.rvm/gems/ruby-1.9.3-p194@my-project/gems/railties-3.2.6/lib/rails/initializable.rb:54:in `each'
$HOME/.rvm/gems/ruby-1.9.3-p194@my-project/gems/railties-3.2.6/lib/rails/initializable.rb:54:in `run_initializers'
$HOME/.rvm/gems/ruby-1.9.3-p194@my-project/gems/railties-3.2.6/lib/rails/application.rb:137:in `initialize!'
$HOME/.rvm/gems/ruby-1.9.3-p194@my-project/gems/railties-3.2.6/lib/rails/railtie/configurable.rb:36:in `method_missing'
$HOME/work/my-project/test-assets/config/environment.rb:7:in `<top (required)>'
$HOME/.rvm/gems/ruby-1.9.3-p194@my-project/gems/activesupport-3.2.6/lib/active_support/dependencies.rb:251:in `require'
$HOME/.rvm/gems/ruby-1.9.3-p194@my-project/gems/activesupport-3.2.6/lib/active_support/dependencies.rb:251:in `block in require'
$HOME/.rvm/gems/ruby-1.9.3-p194@my-project/gems/activesupport-3.2.6/lib/active_support/dependencies.rb:236:in `load_dependency'
$HOME/.rvm/gems/ruby-1.9.3-p194@my-project/gems/activesupport-3.2.6/lib/active_support/dependencies.rb:251:in `require'
$HOME/.rvm/gems/ruby-1.9.3-p194@my-project/gems/railties-3.2.6/lib/rails/application.rb:103:in `require_environment!'
$HOME/.rvm/gems/ruby-1.9.3-p194@my-project/gems/railties-3.2.6/lib/rails/application.rb:294:in `block (2 levels) in initialize_tasks'
$HOME/.rvm/gems/ruby-1.9.3-p194@my-project/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `call'
$HOME/.rvm/gems/ruby-1.9.3-p194@my-project/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `block in execute'
$HOME/.rvm/gems/ruby-1.9.3-p194@my-project/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `each'
$HOME/.rvm/gems/ruby-1.9.3-p194@my-project/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `execute'
$HOME/.rvm/gems/ruby-1.9.3-p194@my-project/gems/rake-0.9.2.2/lib/rake/task.rb:158:in `block in invoke_with_call_chain'
$HOME/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
$HOME/.rvm/gems/ruby-1.9.3-p194@my-project/gems/rake-0.9.2.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
$HOME/.rvm/gems/ruby-1.9.3-p194@my-project/gems/rake-0.9.2.2/lib/rake/task.rb:144:in `invoke'
$HOME/.rvm/gems/ruby-1.9.3-p194@my-project/gems/actionpack-3.2.6/lib/sprockets/assets.rake:94:in `block (2 levels) in <top (required)>'
$HOME/.rvm/gems/ruby-1.9.3-p194@my-project/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `call'
$HOME/.rvm/gems/ruby-1.9.3-p194@my-project/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `block in execute'
$HOME/.rvm/gems/ruby-1.9.3-p194@my-project/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `each'
$HOME/.rvm/gems/ruby-1.9.3-p194@my-project/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `execute'
$HOME/.rvm/gems/ruby-1.9.3-p194@my-project/gems/rake-0.9.2.2/lib/rake/task.rb:158:in `block in invoke_with_call_chain'
$HOME/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
$HOME/.rvm/gems/ruby-1.9.3-p194@my-project/gems/rake-0.9.2.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
$HOME/.rvm/gems/ruby-1.9.3-p194@my-project/gems/rake-0.9.2.2/lib/rake/task.rb:176:in `block in invoke_prerequisites'
$HOME/.rvm/gems/ruby-1.9.3-p194@my-project/gems/rake-0.9.2.2/lib/rake/task.rb:174:in `each'
$HOME/.rvm/gems/ruby-1.9.3-p194@my-project/gems/rake-0.9.2.2/lib/rake/task.rb:174:in `invoke_prerequisites'
$HOME/.rvm/gems/ruby-1.9.3-p194@my-project/gems/rake-0.9.2.2/lib/rake/task.rb:157:in `block in invoke_with_call_chain'
$HOME/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
$HOME/.rvm/gems/ruby-1.9.3-p194@my-project/gems/rake-0.9.2.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
$HOME/.rvm/gems/ruby-1.9.3-p194@my-project/gems/rake-0.9.2.2/lib/rake/task.rb:144:in `invoke'
$HOME/.rvm/gems/ruby-1.9.3-p194@my-project/gems/actionpack-3.2.6/lib/sprockets/assets.rake:60:in `block (3 levels) in <top (required)>'
$HOME/.rvm/gems/ruby-1.9.3-p194@my-project/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `call'
$HOME/.rvm/gems/ruby-1.9.3-p194@my-project/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `block in execute'
$HOME/.rvm/gems/ruby-1.9.3-p194@my-project/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `each'
$HOME/.rvm/gems/ruby-1.9.3-p194@my-project/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `execute'
$HOME/.rvm/gems/ruby-1.9.3-p194@my-project/gems/rake-0.9.2.2/lib/rake/task.rb:158:in `block in invoke_with_call_chain'
$HOME/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
$HOME/.rvm/gems/ruby-1.9.3-p194@my-project/gems/rake-0.9.2.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
$HOME/.rvm/gems/ruby-1.9.3-p194@my-project/gems/rake-0.9.2.2/lib/rake/task.rb:144:in `invoke'
$HOME/.rvm/gems/ruby-1.9.3-p194@my-project/gems/rake-0.9.2.2/lib/rake/application.rb:116:in `invoke_task'
$HOME/.rvm/gems/ruby-1.9.3-p194@my-project/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block (2 levels) in top_level'
$HOME/.rvm/gems/ruby-1.9.3-p194@my-project/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `each'
$HOME/.rvm/gems/ruby-1.9.3-p194@my-project/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block in top_level'
$HOME/.rvm/gems/ruby-1.9.3-p194@my-project/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
$HOME/.rvm/gems/ruby-1.9.3-p194@my-project/gems/rake-0.9.2.2/lib/rake/application.rb:88:in `top_level'
$HOME/.rvm/gems/ruby-1.9.3-p194@my-project/gems/rake-0.9.2.2/lib/rake/application.rb:66:in `block in run'
$HOME/.rvm/gems/ruby-1.9.3-p194@my-project/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
$HOME/.rvm/gems/ruby-1.9.3-p194@my-project/gems/rake-0.9.2.2/lib/rake/application.rb:63:in `run'
$HOME/.rvm/gems/ruby-1.9.3-p194@my-project/gems/rake-0.9.2.2/bin/rake:33:in `<top (required)>'
$HOME/.rvm/gems/ruby-1.9.3-p194@my-project/bin/rake:23:in `load'
$HOME/.rvm/gems/ruby-1.9.3-p194@my-project/bin/rake:23:in `<main>'
Tasks: TOP => environment
rake aborted!
Command failed with status (1): [$HOME/.rvm/rubies/ruby-1.9.3-p194/bi...]
$HOME/.rvm/gems/ruby-1.9.3-p194@my-project/gems/rake-0.9.2.2/lib/rake/file_utils.rb:53:in `block in create_shell_runner'
$HOME/.rvm/gems/ruby-1.9.3-p194@my-project/gems/rake-0.9.2.2/lib/rake/file_utils.rb:45:in `call'
$HOME/.rvm/gems/ruby-1.9.3-p194@my-project/gems/rake-0.9.2.2/lib/rake/file_utils.rb:45:in `sh'
$HOME/.rvm/gems/ruby-1.9.3-p194@my-project/gems/rake-0.9.2.2/lib/rake/file_utils_ext.rb:39:in `sh'
$HOME/.rvm/gems/ruby-1.9.3-p194@my-project/gems/rake-0.9.2.2/lib/rake/file_utils.rb:80:in `ruby'
$HOME/.rvm/gems/ruby-1.9.3-p194@my-project/gems/rake-0.9.2.2/lib/rake/file_utils_ext.rb:39:in `ruby'
$HOME/.rvm/gems/ruby-1.9.3-p194@my-project/gems/actionpack-3.2.6/lib/sprockets/assets.rake:12:in `ruby_rake_task'
$HOME/.rvm/gems/ruby-1.9.3-p194@my-project/gems/actionpack-3.2.6/lib/sprockets/assets.rake:21:in `invoke_or_reboot_rake_task'
$HOME/.rvm/gems/ruby-1.9.3-p194@my-project/gems/actionpack-3.2.6/lib/sprockets/assets.rake:29:in `block (2 levels) in <top (required)>'
$HOME/.rvm/gems/ruby-1.9.3-p194@my-project/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `call'
$HOME/.rvm/gems/ruby-1.9.3-p194@my-project/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `block in execute'
$HOME/.rvm/gems/ruby-1.9.3-p194@my-project/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `each'
$HOME/.rvm/gems/ruby-1.9.3-p194@my-project/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `execute'
$HOME/.rvm/gems/ruby-1.9.3-p194@my-project/gems/rake-0.9.2.2/lib/rake/task.rb:158:in `block in invoke_with_call_chain'
$HOME/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
$HOME/.rvm/gems/ruby-1.9.3-p194@my-project/gems/rake-0.9.2.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
$HOME/.rvm/gems/ruby-1.9.3-p194@my-project/gems/rake-0.9.2.2/lib/rake/task.rb:144:in `invoke'
$HOME/.rvm/gems/ruby-1.9.3-p194@my-project/gems/rake-0.9.2.2/lib/rake/application.rb:116:in `invoke_task'
$HOME/.rvm/gems/ruby-1.9.3-p194@my-project/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block (2 levels) in top_level'
$HOME/.rvm/gems/ruby-1.9.3-p194@my-project/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `each'
$HOME/.rvm/gems/ruby-1.9.3-p194@my-project/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block in top_level'
$HOME/.rvm/gems/ruby-1.9.3-p194@my-project/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
$HOME/.rvm/gems/ruby-1.9.3-p194@my-project/gems/rake-0.9.2.2/lib/rake/application.rb:88:in `top_level'
$HOME/.rvm/gems/ruby-1.9.3-p194@my-project/gems/rake-0.9.2.2/lib/rake/application.rb:66:in `block in run'
$HOME/.rvm/gems/ruby-1.9.3-p194@my-project/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
$HOME/.rvm/gems/ruby-1.9.3-p194@my-project/gems/rake-0.9.2.2/lib/rake/application.rb:63:in `run'
$HOME/.rvm/gems/ruby-1.9.3-p194@my-project/gems/rake-0.9.2.2/bin/rake:33:in `<top (required)>'
$HOME/.rvm/gems/ruby-1.9.3-p194@my-project/bin/rake:23:in `load'
$HOME/.rvm/gems/ruby-1.9.3-p194@my-project/bin/rake:23:in `<main>'
Collaborator

betamatt commented Jun 26, 2012

Confirmed reproducible. This has annoyed the hell out of me on a project but I didn't realize it was DJ causing it.

Looking at the pull request it looks like this bug has been waiting for four months for somebody to make a suggested change so they get credit. Let's move on!!! This is really annoying because it breaks asset pre-compilation during slug compilation on heroku and needs to get fixed. If you need another pull request let me know.

Owner

albus522 commented Sep 24, 2014

4.0.4 no longer does this.

@albus522 albus522 closed this Sep 24, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment