Work_smarter
Work_smarter is a simple wrapper for Delayed::Job that helps you autoscale workers when deployed on Heroku.
Please note: This is still very early days for Work_smarter, there's very little (read: zero) test coverage - and we've yet to even put it into production.
Configuration
Setup delayed_job as per the instructions on Heroku.
Add Work_smarter to your Gemfile:
gem "work_smarter"
Add a /config/work_smarter.yml
file to your Rails 3 project directory and add the following:
defaults: &defaults max_workers: 1 min_workers: 0 application_name: my_heroku_application api_key: your_api_key backgroundjob_name: worker #default should be 'worker'
development: <<: *defaults
test: <<: *defaults
production: <<: *defaults
Usage
Work_smarter is set up to (try and) be as abstract as possible. Queuing a function works similar to delayed_job, just call:
Work_smarter.queue object, :function, [arg1, arg2]
For example:
Work_smarter.queue @image, :resize, => 900, :height => 450 # -- or -- Work_smarter.queue UserMailer.send_registration_notification(@user), :deliver
Work_smarter will automatically add and remove workers as the queue fills up and empties, respectively.
Notes
This is a modified version of the Komodo gem. I changed some behaviour because the Komodo gem used deprecated Heroku commands. I renamed and created this gem because i had namespace issues with a fork of the Komodo gem.
As stated above, this is really a pre-alpha of Work_smarter, as such the scaling is very basic; Work_smarter just ramps straight up to the user-configured maximum.