Skip to content

Instantly share code, notes, and snippets.

@vinh0604
Forked from maggix/scale_dynos.rake
Last active August 29, 2015 13:58
Show Gist options
  • Select an option

  • Save vinh0604/9994860 to your computer and use it in GitHub Desktop.

Select an option

Save vinh0604/9994860 to your computer and use it in GitHub Desktop.

I wanted a way to scale up and down the dynos in Heroku based on time of day. To do so, I added the scheduler add-on to heroku heroku addons:add scheduler

In my Rails app, I added the scale_dynos.rake file in /lib/tasks/ and the following line to the Gemfile: gem 'heroku-api', '~> 0.3.17', :require => false

Now I can run heroku run rake scale_dynos:up (and down) through the command line, as well as scheduling the command rake scale_dynos:up in the Scheduler add-on. a

namespace :scale_dynos do
require 'heroku-api'
desc "Scale UP dynos"
task :up do
heroku = Heroku::API.new(:api_key => ENV['HEROKU_API_KEY'])
heroku.post_ps_scale(ENV['APP_NAME'], 'web', 2)
end
desc "Scale DOWN dynos"
task :down do
heroku = Heroku::API.new(:api_key => ENV['HEROKU_API_KEY'])
heroku.post_ps_scale(ENV['APP_NAME'], 'web', 1)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment