15

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!

1 Answer 1

17

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.