Here's a simple example of how to create and run workers in Ruby on Rails. If you haven't already, please start with our SimpleWorker in 5 minutes article, which uses just the Ruby language. This example takes it the next step to use it within a Rails environment. Confirm Ruby 1.9 or above.SimpleWorker uses Ruby 1.9 or above and so if you're still on Ruby 1.8.7, you'll need to upgrade your Ruby version. Configure SimpleWorker GemRails 3For Rails 3.X, add the following to your Gemfile:
Rails 2For Rails 2.X, add the following to your
Configure SimpleWorker Access KeysThen create a file at Use this config block for >v2.x of the simple_worker gem If you're using v1.x of the simple_worker gem then use the following config block:
Configure SimpleWorker Worker Path NOTE: This is only required in Rails < 3. And finally, add the workers directory to your load paths. In environment. rb:
Create a WorkerNow that things are configured, let's queue up a worker from an action. First, create a workers directory at:
Now create a file called
Queue up the Worker in the CloudLet's say we have a controller called
Now just visit your welcome controller, eg: http://localhost:3000/welcome and this job will be queued up! You can visit your SimpleWorker dashboard at www.simpleworker.com to get the status of the job or make use of the To run jobs with a higher priority, just pass in a priority when you queue them.
Check out this github repository for a full Rails example. |
Ruby > Getting Started >