Search code examples
ruby-on-railsdelayed-job

Use separate DB for delayed_job


I have a situation where I need to have delayed_job use a custom backend 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.


Solution

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