You can scale heroku dynos on a schedule by creating a script that uses the Heroku API. You then make an entry in your Procfile and call it via the Heroku Scheduler add-on. Here's how:
First you'll need to add the 'heroku' python module to your requirements.txt
:
heroku==0.1.2
Next, create a config var that contains your API key, so your script can use the API.
heroku config:add HEROKU_API_KEY=your_api_key_string
You can find your API key on your heroku account page.
Now you'll be able to write a python script that scales your dynos. Here's a very basic script that accepts the number of dynos as a command-line argument.
import os
import sys
import heroku
"""Scale heroku web processes using the heroku python API."""
# you may want to add better argument processing, use argparse, etc.
dynos = int(sys.argv[1])
cloud = heroku.from_key(os.environ.get('HEROKU_API_KEY'))
app = cloud.apps['your_app_name']
try:
# you may want to add a maximum dyno check here to prevent costly mistakes ;)
webproc = app.processes['web']
webproc.scale(dynos)
except KeyError:
# note: scaling to 0 dynos or attempting to scale up if 0 web dynos exist
# both throw this error. Make sure you have at least one dyno.
print >> sys.stderr, "Could not scale web processes - are there 0 web dynos running?"
Then you can either define your entire task inside the Heroku Scheduler web page, or define it inside your Procfile and call the Procfile process name from the web page. I prefer the latter, as it makes it easy to update or change the process without having to log in to heroku's website.
So, create entries in your Procfile:
scale_up: python scale.py 2
scale_down: python scale.py 1
And then schedule them:
And voila! Your dynos will now scale up or down at the specified time of day.
--
Note that once you have created a scheduled task on the Scheduler web page you can't edit the time of day it runs, but if you create a new task you can set the time day and then delete your old task.
Note 2: The heroku python API seems to throw a KeyError if you try to scale down to 0 dynos, or if you try to scale up if 0 web dynos currently exist. To avoid both, just don't scale down to 0 dynos.