Heroku: How to auto start Python app on deploy?

Viewed 885

I've got a Heroku app which automatically deploys when I'm pushing changes to GitHub. It's a Discord Bot (written in python).

Now I want to automatically start this python script when I'm going to deploy (It should run 24/7 until it's stopped by a new deploy).

I read about Dynos but don't know how to use them. I already added the Procfile with bot: python bot.py but this won't auto start the app. The Dyno is only shown in the resources tab on the dashboard. Using heroku ps -a myapp it responds with No dynos on ⬢ myapp. The bot: python bot.py Dyno in the dashboard also can't be started through that switch.

Screenshot: The switch can't be activated

So I tried to use release: python bot.py which starts the bot but after another deploy the processes are stacking up and the bot is running multiple times.

1 Answers

Don't use a release command for this.

release commands run once as part of the deploy, then they're done. Your application should probably be set up as a web process (if it's supposed to respond to HTTP requests):

web: python myapp.py

or a worker process (if it isn't):

worker: python myapp.py
Related