Forums

Periodically call Manage.py or other script in Scheduled tasks

I'm sorry, but I'm new and don't really understand how Schedules tasks works.

  1. How does PA know which environment to execute the script or command in? Because there is no place to specify that "I want you to run x command while inside this virtualenv "

  2. Let's say I want to periodically call "python manage.py some_command" in my for a web app. How do I add this to scheduled tasks? And how do I specify the app it's meant for??

I have more questions, but these 2 are the most pressing. Please I'd appreciate any help. Thanks.

1/ create a virtual env, py36 for instance and then in a console, just activate it : workon py36

2/ Just create a task like this one, for instance :

/home/USER/.virtualenvs/py36/bin/python /home/USER/app/v1/main_script.py

replacing user with your user

here py36 is a virtualenv I created ...

@123decrypto's tip is correct. Here's a help page on this exact topic: http://help.pythonanywhere.com/pages/VirtualEnvInScheduledTasks

Thanks for your help! You advice has cleared some of my fog.

Is there anyway to run manage.py my_command as a scheduled task?

Using exactly the same technique yes. Just point your virtualenv python at your manage.py script, and then add my_command as the third argument...