开发者

Use separate DB for delayed_job

I have a situation where I need to have delayed_job use a custom backend开发者_StackOverflow中文版 on a separate DB/table.

So essentially force it to use a separate schema vs. the one my app primarily uses.

Any ideas on how to do this? Thanks in advance.


you could make some of your models connect to a different database and use different tables.

Specify the configurations for your new db in the database.yml

delayed_jobs_db_connection:
  adapter: mysql # or any other adapter
  database: delayed_jobs_db
  username: root
  password:
  host: localhost

And in the model one would establish the connection to this database using establish_connection. You could also specify all the config directly in the model, keeping it in a config is just a better way. Hope this helps.


I know this has been asked quite a bit time ago, but I faced the same challenge and this easy approach worked for me:

Just added in the top of the file:

require 'delayed_job'
require 'delayed_job_active_record'
class Delayed::Job
  establish_connection {"adapter"=>"mysql2",
   "host"=>"127.0.0.1",
   "username"=>"root",
   "password"=>"aaaaa",
   "port"=>3306,
   "database"=>"users",
   "reconnect"=>true,
   "pool"=>10}
end
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜