Go – django “manage.py index” does not execute as a cron job

djangopinax

I am trying to develop a site using pinax.
To index the models using djapian I've been trying to run "manage.py index" as a cron job but keep getting a pinax error. "Error: No module named notification". However the task executes correctly when i run it from the shell. My crontab definition is as follows:

SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/mypath/test_project

# m h dom mon dow user  command
*/1 *   * * *   root    python /root/mypath/test_project/manage.py index >>/tmp/backup.log 2>&1

Can anyone explain why I am receiving this error?

Best Answer

Your error is probably because you don't have your PYTHONPATH set properly, especially to include the path to the "notification" module. You also need to set the DJANGO_SETTINGS_MODULE path, if it isn't already set in your environment.

Here's a shell script I use to wrap my own django based cron task:

#!/bin/sh
DJANGO_SETTINGS_MODULE=mysettings
export DJANGO_SETTINGS_MODULE

PYTHONPATH=/path/to/python_libs:/path/to/my_django_apps
export PYTHONPATH

/path/to/python /path/to/my_django_script