How to connect to a database in IronWorker using ActiveRecord?

I have a Rails application that uses IronWorker and I need to connect to my database from a working one. How to do it?

+5
source share
2 answers

The employer needs to explicitly establish a connection to the database, since it does not work in your application, so you need to transfer the connection information to your employee. You can do this in a workload as follows:

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'])
+7
source

I posted a blog post . Hope this helps!

In a nutshell, however, storing the database configuration in environment variables makes the process easier.

+2
source

All Articles