简体   繁体   中英

how to start Crontab in Django Project locally?

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?

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.

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'

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.

python manage.py runserver 

启动服务器后,crontab将根据settings.py中指定的时间自动执行。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM