I would like to run a python script on Heroku, but I would like to run it only once and stop at the end of the script.
Right now my script is running endlessly, so at the end of it, it restarts from the beginning.
How can I stop it at the end of the script ?
Right now my Procfile look the following:
web: python ValueAppScript.py
worker: python ValueAppScript.py
First of all, you probably don't want to declare the same command as both a web
and a worker
. If your script listens for HTTP requests it should be a web
process, otherwise a worker
makes more sense:
worker: python ValueAppScript.py
Since you don't want your worker running all the time, scale it down to zero dynos:
heroku ps:scale worker=0
If you wish to run it once interactively, you can use heroku run
:
heroku run python ValueAppScript.py
If you want it to run on a schedule, e.g. once per day, you can use the Heroku Scheduler. Since you have defined this as a worker
process you should be able to just use worker
as the command.