Travis Reeder
Travis Reeder

Reputation: 41083

How do I connect to a database in IronWorker using ActiveRecord?

I have a Rails application that is using IronWorker and I need to connect to my database from the worker. How do I do that?

Upvotes: 5

Views: 1077

Answers (2)

Chiedo
Chiedo

Reputation: 7544

I whipped up a blog post on this. Hopefully it helps!

In a nut shell though, storing your database configurations in environment variables makes it easy.

Upvotes: 2

Travis Reeder
Travis Reeder

Reputation: 41083

The worker needs to make a connection to the database explicitly since it is not running within your application so you need to pass the connection information to your worker. You can do this in the worker payload like so:

client = IronWorkerNG::Client.new
task = client.tasks.create('MyWorker', 'database' => Rails.configuration.database_configuration[Rails.env])

Then inside your worker:

ActiveRecord::Base.establish_connection(params['database'])

Upvotes: 7

Related Questions