Reputation: 12989
Using the heroku CLI it is possible to scale dynos like so:
$ heroku ps:scale web=1
But I'd like to be able to scale dynos from within my node app (running on heroku, so I can't just exec
the above command because the CLI isn't available), e.g. to respond dynamically to changes in load.
I am vaguely familiar with the heroku client package, but can't see how it could be used for dyno scaling.
Upvotes: 2
Views: 220
Reputation: 12989
So curiousity got the better of me, and I seem to have worked out an answer to my own question...
The key is to use the Heroku API, which is accessed in the node app using the heroku-client package mentioned in my question.
The Heroku API has a Formation Update interface, which allows you to set the scale (or quantity) of the web dynos.
The following example scales the web dyno to 2:
var Heroku = require('heroku-client');
var heroku = new Heroku({ token: process.env.HEROKU_API_TOKEN });
heroku.patch('/apps/yourappname/formation/web', { body: {"quantity": 2} }).then(response => {
console.log('patch response: ' + JSON.stringify(response));
});
... where yourappname
is of course your app's name.
Upvotes: 3