Search code examples
herokucloudflare

Any way to distinguish between Heroku's scheduled dyno restarts and a new build?


I have some code in my app that purges our cache (using Cloudflare's API) every time it starts up so that whenever a change to the website is deployed it shows up instantly for everyone instead of the old version remaining in Cloudflare's cache indefinitely.

Heroku restarts my dyno every 24 hours. This purges Cloudflare for no reason, causes a large spike in traffic, and messes with analytics.

Is there a way to detect on startup if this app restart is occurring due to an actual Heroku deploy, or just due to their daily restart?

One way I've considered is using GitHub's public API to check on startup if a commit has been pushed to master in the last hour, but that seems like a hack and there is probably a better way.


Solution

  • I gave my app access (via environment variables) to my own Heroku API. This allows it to query the API, asking when its own most recent release was. If the most recent release was more than 24 hours ago, we do not purge Cloudflare. Code is here https://github.com/ImpactDevelopment/ImpactServer/commit/db1cced1ed298b933cee87457eaa844f60974f60#diff-12a774f9437b88d4b4ebbd4e2ab726abR25

    This detects anything that causes the app to be rereleased, including code changes, env variable changes, add-on changes, etc.