Created
April 15, 2015 06:39
-
-
Save Agowan/392b9f4d8f875c1bea58 to your computer and use it in GitHub Desktop.
How to schedule heroku prcesses.
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
# encoding: utf-8 | |
require 'heroku-api' | |
namespace :heroku do | |
desc "Scale down the processes during business hours" | |
task :spin_down => :environment do | |
app = ENV['HEROKU_APP'] | |
heroku = Heroku::API.new(:api_key => ENV['HEROKU_API_KEY']) | |
heroku.put_formation(app, 'web' => '1X') | |
heroku.post_ps_scale(app, 'web', 1) | |
end | |
desc "Scale down the processes during none business hours" | |
task :spin_up => :environment do | |
if [1,2,3,4,5].include?(Date.today.wday) | |
app = ENV['HEROKU_APP'] | |
heroku = Heroku::API.new(:api_key => ENV['HEROKU_API_KEY']) | |
heroku.put_formation(app, 'web' => '2X') | |
heroku.post_ps_scale(app, 'web', ENV['HEROKU_WORK_HOUR_DYNOS'].to_i) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment