Created
March 13, 2012 12:46
-
-
Save mscottford/2028552 to your computer and use it in GitHub Desktop.
Rake task for restarting Heroku workers
This file contains hidden or 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
# Add `gem 'heroku-api', :git => 'https://github.com/heroku/heroku.rb.git'` to your Gemfile | |
# Set the APP_NAME environment variable to the name of the Heroku app you wish to control. | |
# Set the HEROKU_API_KEY environment variable to the API key found on the Heroku 'My Account' page. | |
# You can now create a scheduler instance that runs `bundle exec rake heroku:workers:restart` to automate | |
# restarting workers at a regular interval. | |
namespace :heroku do | |
namespace :workers do | |
task :restart do | |
heroku = Heroku::API.new | |
response = heroku.get_ps(ENV['APP_NAME']) | |
workers = response.body.map {|item| item['process'] }.select { |item| item =~ /worker/ } | |
workers.each do |worker| | |
puts "Restarting #{worker}" | |
heroku.post_ps_restart(ENV['APP_NAME'], 'ps' => worker) rescue nil | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi - this script uses the Sunset version of the Heroku API and will no longer work.