This is some starter worker code that users the iron_consumer gem: https://github.com/iron-io/iron_consumer
You can run it as is to test it, then modify it as you see fit.
Let's run the quick example first:
- Clone this repo
git clone https://github.com/iron-io/iron_consumer_starter.git
- Make a copy of
example.config.yml
calledconfig.yml
and a copy ofexample.iron.json
callediron.json
and replace all the settings in it especially your token and project id (get these from HUD). TODO: make it so we only need config.yml. - Run
bundle update
- Now let's add a dummy message to a queue on IronMQ (run it a few times if you want):
ruby addmsg.rb
- And process it:
ruby local.rb
- Run
iron_worker upload consumer
- Add another message (or many) for the worker:
ruby addmsg.rb
- Queue up a worker to process the queue:
iron_worker queue consumer
- Boom! Check out the results in HUD.
Ok, now that we got the example running, we can modify the worker to do whatever we want, whether that's processing some data and stuffing it in a database, processing an image, sending out notifications via email, SMS, or to mobile phones.
- Modify
usersetup.rb
, put in stuff here that only needs to happen once like make database connections or - Update Gemfile with gems you need (and bundle update of course)
- Modify
usercode.rb
with what you want your worker to do. - Test it with
ruby local.rb
- Upload it to IronWorker again.
- Queue up a job again to test it.
Alerts will start this runner when there's things in the queue to process and will autoscale if your queue grows.
- Run
ruby setalerts.rb
1 Runruby addmsg.rb
to put a message on the queue and your worker will start automatically! BOOM!
or Schedule it to have it running all the time:
- Schedule it:
iron_worker schedule --run-every 60 consumer