Skip to content

Instantly share code, notes, and snippets.

@maggix
Last active January 4, 2016 20:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save maggix/8676595 to your computer and use it in GitHub Desktop.
Save maggix/8676595 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_ACCOUNT_API_KEY'])
heroku.post_ps_scale(ENV['HEROKU_APP_NAME'], 'web', 2)
end
desc "Scale DOWN dynos"
task :down do
heroku = Heroku::API.new(:api_key => ENV['HEROKU_ACCOUNT_API_KEY'])
heroku.post_ps_scale(ENV['HEROKU_APP_NAME'], 'web', 1)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment