Iron Worker 101 Rails example
IronWorker integrates easily into a Rails application and lets you run and schedule workers in the cloud. After some config (iron.json, worker_name.worker files), it's matter of uploading the workers to IronWorker (inside or outside your app) and then calling them within your app when you want to.
This example show how to work with iron_worker under Rails environment
Set proper configuration in config_development.yml
run 'rake iron_worker:upload'
run 'rails s'
Go to http://localhost:3000 and test
Q: Where should you place workers?
A: Better to place workers in rails_root/workers dir like in example worker dir
Q: How do you upload workers?
A: You can upload workers in a number of ways:
- rake task (rake iron_worker:upload) - iron_worker.rake - use this approach when you have deploy script or scenario and you want control when and which workers you want to upload
- initializer - iron_worker - use this approach when you want to be ensure that all your workers always are up to date (but don't forget that workers will be uploaded every time you restart rails)
- controller/model - controller - we don't recommend to upload workers from controllers or models, but with this approach you could upload/modify workers without touching rails
Q: How do you use ActionMailer within a worker?
A: Simple. Just take the following steps:
Important note, if you're passing ActionMailer config hash as worker params you need to convert them on worker side to 'valid' hash(example).
Q: How do you use Models and/or connect to a database within a worker?
A: It's easy. Here's how:
Q: How to get processed data back from worker?
A: There are few ways: