Schedule Heroku to restart dynos every 10 or so minutes

梦想的初衷 提交于 2020-04-15 17:13:51

问题


I am developing a REST api with Node.js on Heroku, and one the drivers is giving me problems (I reported that to the driver creator already), but basically a restart of the dynos every half an hour or so seems to fix this. I was hoping y'all could help me with writing a script for scheduler or something similar to restart the dynos automatically every 10 or so minutes as a temporary fix.

p.s. I checked out the scheduler documentation, but it didn't make much sense

Thanks!


回答1:


You can do what you're asking by doing the following:

  • Create a script in your project that makes a Heroku Platform API request to restart your dynos. The API call documentation can be found here: https://devcenter.heroku.com/articles/platform-api-reference#dyno-restart-all

  • Provision the Heroku Scheduler addon.

  • Go into Heroku Scheduler's web UI, and tell it to run your restart script every hour (or whatever time period works for you).

This is the best 'pragmatic' way to accomplish this.




回答2:


The steps provided by @rdegges require additional authentication token in the request. Adding more details:

  1. Create Auth Token using Heroku CLI by running this command as mentioned on Heroku platform API

    heroku authorizations:create

  2. Install the Heroku Scheduler add-on into your Heroku application.

  3. Open scheduler and go to add job. Enter the following command in the job editor. This command performs restart the dyno.

curl -n -X DELETE https://api.heroku.com/apps/NameofYourApplication/dynos \ -H "Content-Type: application/json" \
-H "Accept: application/vnd.heroku+json; version=3" -H "Authorization: Bearer TokenValueGenereatedInStep1"

Verify in the Heroku app logs, if the scheduler job is running on the set time.



来源:https://stackoverflow.com/questions/43926740/schedule-heroku-to-restart-dynos-every-10-or-so-minutes

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