How do I connect to a database in IronWorker using ActiveRecord?
iron.io, ironworker
Solution
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'])
Problem
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?