Skip to content

Instantly share code, notes, and snippets.

@mscottford
Created March 13, 2012 12:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mscottford/2028552 to your computer and use it in GitHub Desktop.
Save mscottford/2028552 to your computer and use it in GitHub Desktop.
Rake task for restarting Heroku workers
# 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
@tomgallagher
Copy link

Hi - this script uses the Sunset version of the Heroku API and will no longer work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment