0

I have followd the following links for running a cron job :

django - cron

custom management commands

but all of these ways work if i run commands like:

or

python manage.py crontab add

or

   python manage.py runcron

but i don't want to do cron jobs without django server running i mean i want to run django server and it automatically call a certain function by itself during running of server for example every (say) 5 minutes.

KinGover
  • 11
  • 1
  • 4
  • have you looked into an django init script? [link](http://www.charleshooper.net/blog/controlling-django-apps-with-an-init-script) – crownedzero Nov 19 '13 at 16:14
  • does it work first time at start of running server? if not please give me a simple example that call a function every 5 minutes – KinGover Nov 19 '13 at 16:18
  • it allows you to daemonize django (run as a service essentially) you can start django on system startup. Or create a bash cron to check if django is running and start it. – crownedzero Nov 19 '13 at 16:23
  • so it can't help me to call a function periodically? – KinGover Nov 19 '13 at 16:32

2 Answers2

0

If I understand correctly you can't use django cron if django isn't running; so create a bash script to check if django is running and if not start it.

MYPROG="myprog"
RESTART="myprog params"
PGREP="/usr/bin/pgrep"
# find myprog pid
$PGREP ${MYPROG}
# if not running
if [ $? -ne 0 ]
then
   $RESTART
fi

Then for your cron:

*/5 * * * * /myscript.sh

This is off the cuff and not individualized to your setup but it's as good as any to start.

crownedzero
  • 496
  • 1
  • 7
  • 18
0

Let me see if I can elaborate:

On Linux you'll use cron Windows will use at; these are system services not to be confused with Django. They are essentially scheduled tasks.

The custom management commands is essentially a script that you point the cron job to.

You'll need to do some homework on what a cron job is (if you're using Linux) and see how to schedule a reoccuring task and how to have it issue the custom command. This is my understanding of what you're trying to do. If it's not you need to clarify.

crownedzero
  • 496
  • 1
  • 7
  • 18