0

I still pretty new to the use of crontab in Django. I have followed the instruction in this link https://hprog99.wordpress.com/2014/08/14/how-to-setup-django-cron-jobs/ to help me set up my method, my_scheduled_job() in cron.py file, which I want to call every five minutes.

Here is my updated setting.py

INSTALLED_APPS = ( 'django_crontab', ...) CRONJOBS = [ ('*/5 * * * *', 'myproject.cron.my_scheduled_job') ]

After which I ran this: python manage.py crontab add

Output: adding cronjob: (d0428c9ae8227ed78b17bf32aca4bc67) -> ('*/5 * * * *', 'cinemas.cron.my_scheduled_job')

Next: Nothing happens.

How do I start this cron job locally? Is there a way to test if my job ran normally?

pfnuesel
  • 14,093
  • 14
  • 58
  • 71
curiousDog
  • 83
  • 1
  • 8
  • I resolved this by running python manage.py runserver. Function started running at every 5th minute interval yay! – curiousDog Nov 07 '16 at 15:58

4 Answers4

2

In django you can setup cron using django-chronograph or chronograph.

Django-chronograph is a simple application that allows you to control the frequency at which a Django management command gets run.

Step 1: Create management command of your task in django. For creating django management command refer Writing custom django-admin commands.

Step 2: After creating django management command configure command in cronograph.

Hope this helps you.

NIKHIL RANE
  • 4,012
  • 2
  • 22
  • 45
  • django-chronograph is unmaintained. Its fork is doing much better and has support for Django 2.0 and Django 2.1: https://github.com/chrisspen/django-chroniker – Menda Apr 12 '19 at 13:34
1

first, you must Specify your project profile, then add the cron job, if your project name is foo, then it is like:

export FOO_PROFILE = 'local'
python manage.py crontab add

and , before run above command, in your settings.local you should config cron environment first, something like:

# django-crontab config
CRONTAB_DJANGO_SETTINGS_MODULE = 'gold.settings.local'
李东勇
  • 190
  • 1
  • 10
0

Is there a test tab in Python? Probably a simulation somewhere to get tutorial. Try key word search in agent answer or similar help and command program.

0
python manage.py runserver 

Once you start the server, crontab will automatically execute based on the time specified in settings.py.

curiousDog
  • 83
  • 1
  • 8