Created
May 20, 2011 04:47
-
-
Save christocracy/982376 to your computer and use it in GitHub Desktop.
Setting up DelayedJob Workers on Heroku using DataMapper hooks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if ENV["HEROKU_APP"] | |
# Spin-up workers when jobs are created | |
Delayed::Job.after :create do | |
workers_needed = [Delayed::Job.count + 1, MAX_CONCURRENT_WORKERS].min | |
@username = ENV['HEROKU_USERNAME'] | |
@password = ENV['HEROKU_PASSWORD'] | |
@app = ENV['HEROKU_APP'] | |
client = Heroku::Client.new(@username, @password) | |
client.set_workers(@app, workers_needed) | |
puts "- Initialized Heroku workers for ZipDecoder" | |
end | |
# Spin-down workers as jobs destroyed | |
Delayed::Job.after :destroy do | |
workers_needed = [Delayed::Job.count - 1, 0].max | |
client = Heroku::Client.new(@username, @password) | |
client.set_workers(@app, workers_needed) | |
puts "- Cleaned Up a Delayed Job for ZipDecoder" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment