My database.yml file:

production:
  adapter: mysql2
  database: app_production
  host: 127.0.0.1
  username: root
  password: 12345678
  port: 3306
  pool: 15
  timeout: 5000
  socket: /var/run/mysqld/mysqld.sock

(Removing the socket line does not help)

Path according to my.cnf:

/var/run/mysqld/mysqld.sock

Mysql is running because my app is up, but when I run:

 rake jobs:clear

from the console, I get:

rake aborted!
Mysql2::Error: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
/home/deploy/dispatch/shared/bundle/ruby/2.2.0/gems/mysql2-0.3.18/lib/mysql2/client.rb:70:in `connect'
/home/deploy/dispatch/shared/bundle/ruby/2.2.0/gems/mysql2-0.3.18/lib/mysql2/client.rb:70:in `initialize'
/home/deploy/dispatch/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.1/lib/active_record/connection_adapters/mysql2_adapter.rb:18:in `new'
/home/deploy/dispatch/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.1/lib/active_record/connection_adapters/mysql2_adapter.rb:18:in `mysql2_connection'
/home/deploy/dispatch/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:438:in `new_connection'
/home/deploy/dispatch/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:448:in `checkout_new_connection'
/home/deploy/dispatch/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:422:in `acquire_connection'
/home/deploy/dispatch/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:349:in `block in checkout'
/home/deploy/dispatch/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:348:in `checkout'
/home/deploy/dispatch/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:263:in `block in connection'
/home/deploy/dispatch/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:262:in `connection'
/home/deploy/dispatch/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:567:in `retrieve_connection'
/home/deploy/dispatch/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.1/lib/active_record/connection_handling.rb:113:in `retrieve_connection'
/home/deploy/dispatch/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.1/lib/active_record/connection_handling.rb:87:in `connection'
/home/deploy/dispatch/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.1/lib/active_record/relation.rb:477:in `delete_all'
/home/deploy/dispatch/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.1/lib/active_record/querying.rb:8:in `delete_all'
/home/deploy/dispatch/shared/bundle/ruby/2.2.0/gems/delayed_job-4.0.6/lib/delayed/tasks.rb:4:in `block (2 levels) in <top (required)>'
Tasks: TOP => jobs:clear
1

There are 1 answers

0
sjaime On BEST ANSWER

Delayed job will take the database configuration associated with the rails environment your application is running in.

If you just run rake jobs:clear, it'll run by default in development mode and will try to connect to your development database. If you want delayed_job to connect to your production database, you need to set the environment accordingly, i.e. production:

RAILS_ENV=production rake jobs:clear

By the way, keep the socket line in your database.yml, otherwise it'll default to /tmp/mysql.sock.