Brendan Bernstein
Brendan Bernstein

Reputation: 175

Heroku Scheduler With Python Script

How do I run a python script that is in my main directory with Heroku scheduler?

Normally I run this through the command line with Heroku run python "script.py", but this syntax is clearly not correct for the Heroku Scheduler. Where it says "rake do_something" what should the correct syntax be to run a python script here? I've tried "python script.py" and this does not work either.

Thanks!

Upvotes: 15

Views: 7768

Answers (1)

brennan
brennan

Reputation: 3493

The Heroku Scheduler will try to run any command you give it. For Python, if you added a mytask.py to your app repo, you could have the Scheduler run:

python mytask.py

Instead of waiting for the Scheduler to run to see if the command works as expected, you can also test run it like this:

heroku run python mytask.py  # or heroku run:detached ...
heroku logs --tail

Another way to use the Scheduler would be to extend your app with a cli tool or a script runner that shares the app context. A popular one for Flask is Flask-Script.

Note: the "rake" references in the Heroku Scheduler docs example is for running tasks with ruby.

Upvotes: 17

Related Questions