How can I force delayed_job to use a specific db connection?

Viewed 2993

I have a Rails 3 applications that uses different databases depending on the subdomain. I do this by using "establish_connection" in the ApplicationController.

Now I'm trying to use delayed_job gem to do some background processing, however it uses the database connection that it's active in that moment. It's connecting to the subdomain database.

I'd like to force it to use the "common" database. I've done this for some models calling "establish_connection" in the model like this:

class Customer < ActiveRecord::Base
  establish_connection ActiveRecord::Base.configurations["#{Rails.env}"]
  ...
end

Any idea how can I do this?

1 Answers
Related