If you have hosted your Django app on pythonanywhere.com server and you want to schedule a cron job on the server to execute some task periodically ( daily or hourly) then this article is for you.
Cron jobs are executed after a fixed interval of time, repetitively until stopped explicitly. This may come handy if you want to send bulk mails every hour or you may want to take a backup of your database or basically anything you want to perform periodically.
In another related article we discussed how to host a django app on pythonanywhere.com server for free. In this article we listed benefits of pythonanywhere server and steps to host the app in details.
Article consist of screenshots to help you and a video tutorial showing working of article steps.
First make sure you have created your custom management command which will perform the task. e.g. sending emails or creating backup etc.
First run this command from terminal and check if it is working as expected or not.
Go to schedule tab in your account on pythonanywhere server.
As you can see that you can schedule a cron on daily basis. Hourly basis scheduling is available to paid users only.
Time is given in UTC format.
Select the hours and minutes accordingly and in command path input field enter the complete command with below format.
absolute-path-to-python absolute-path-to-manage.py-file command_name
/home/100rupeekart/VirtualEnv/bin/python3.4 /home/code108/myproject/manage.py send_mail_command
Add the command. To see the output of the command later on, click on the command in list of scheduled commands.