script/delayed_job needs RAILS_ENV #9

Closed
zubin opened this Issue Sep 16, 2009 · 4 comments

Comments

Projects
None yet
3 participants

zubin commented Sep 16, 2009

As you can see, the daemon uses the wrong db credentials unless RAILS_ENV is passed in:

[root@my_server ~]# /home/deploy/my_app/script/delayed_job -e staging start
/home/deploy/rails_apps/my_app/releases/20090916055509/vendor/rails/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb:547:in `real_connect': Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) (Mysql::Error)
    from /home/deploy/rails_apps/my_app/releases/20090916055509/vendor/rails/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb:547:in `connect'
    from /home/deploy/rails_apps/my_app/releases/20090916055509/vendor/rails/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb:199:in `initialize'
    from /home/deploy/rails_apps/my_app/releases/20090916055509/vendor/rails/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb:74:in `new'
    from /home/deploy/rails_apps/my_app/releases/20090916055509/vendor/rails/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb:74:in `mysql_connection'
    from /home/deploy/rails_apps/my_app/releases/20090916055509/vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb:223:in `send'
    from /home/deploy/rails_apps/my_app/releases/20090916055509/vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb:223:in `new_connection'
    from /home/deploy/rails_apps/my_app/releases/20090916055509/vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb:245:in `checkout_new_connection'
    from /home/deploy/rails_apps/my_app/releases/20090916055509/vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb:188:in `checkout'
     ... 19 levels...
    from /home/deploy/my_app/config/../vendor/rails/railties/lib/initializer.rb:112:in `run'
    from /home/deploy/my_app/config/environment.rb:6
    from /home/deploy/my_app/script/delayed_job:3:in `require'
    from /home/deploy/my_app/script/delayed_job:3
[root@my_server ~]# RAILS_ENV=staging /home/deploy/my_app/script/delayed_job -e staging start
[root@my_server ~]# 

Well you can't automatically deduce the rails_env.
You can launch the same application files in dev and prod.
So I guess passing it in argument is the best way.

zubin commented Nov 17, 2009

The -e option was meant to specify the environment (as per my example) but that didn't work, but passing in RAILS_ENV did. Perhaps "delayed_job -h" needs updating.

RAILS_ENV=staging before the command is a shell feature that sets an environment variable- it will work for any rails command (that reads the RAILS_ENV variable). Seems unecessary ever start the -e for some commands, but perhaps that is needed for windows.

zubin commented Jan 31, 2011

I was wanted to point out that although the delayed_job docs indicated the -e flag was the way to set the environment, it wasn't – it had to be set as an environment variable.

@latentflip latentflip pushed a commit to latentflip/delayed_job that referenced this issue Sep 9, 2011

@bkeepers bkeepers Reopen log file in 'w+' mode. closes #9 69ece0d

This issue was closed.

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