How to add and remove Heroku Dynos through platform API

◇◆丶佛笑我妖孽 提交于 2021-01-28 02:14:15

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!