问题
I want to add and remove Heroku Dynos through platform API Just like we do
ps:scale web=0
in Heroku toolbelt CLI.
I have already tried
POST /apps/{app_id_or_name}/dynos/{dyno_id_or_name}/actions/stop
but it doesn't do anything however the response has a status code of 200.
回答1:
As per the dyno stop ps:stop
behavior outlined in this question:
Running ps:stop
on dynos that are part of a scaled process will automatically be restarted. In Private Spaces, ps:stop
will terminate and replace the dedicated instance running the dyno(s). To permanently stop dynos, scale down the process."
To scale down the dynos to 0 through the Platform API, you'll need to use formation API.
Formation List:
GET /apps/{app_id_or_name}/formation
$ curl -n https://api.heroku.com/apps/$APP_ID_OR_NAME/formation \
-H "Accept: application/vnd.heroku+json; version=3"
Formation Update:
PATCH /apps/{app_id_or_name}/formation/{formation_id_or_type}
$ curl -n -X PATCH https://api.heroku.com/apps/$APP_ID_OR_NAME/formation/$FORMATION_ID_OR_TYPE \
-d '{
"quantity": 1,
"size": "standard-1X"
}' \
-H "Content-Type: application/json" \
-H "Accept: application/vnd.heroku+json; version=3"
Sending quantity = 0 as a parameter will scale the dyno process to zero.
来源:https://stackoverflow.com/questions/63806415/how-to-add-and-remove-heroku-dynos-through-platform-api