Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 933
Brendan Bernstein Avatar asked Dec 18 '16 23:12

Brendan Bernstein


People also ask

Can you run a Python script in task scheduler?

In order to schedule the Python script using the Windows Scheduler: Open the Windows Control Panel and then click on the Administrative Tools. Double-click on the Task Scheduler, and then choose the option to 'Create Basic Task…' Type a name for your task (you can also type a description if needed), and then press Next ...

Can I run a script on Heroku?

Heroku allows you to publish your web application with just one click. And if you're familiar with it, then you already know that you can use shell scripts or launch commands in the terminal to deploy your applications to the cloud.


1 Answers

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.

like image 152
brennan Avatar answered Oct 19 '22 03:10

brennan