Tivix / django-cron

Write cron business logic as a Python class and let this app do the rest! It enables Django projects to schedule cron tasks, tracks their success / failures, manages contention (via a cache) etc. Basically takes care of all the boring work for you :-)
www.tivix.com
MIT License
900 stars 193 forks source link

Not starting schedule jobs every 2 minutes #29

Closed cis-yogesh closed 10 years ago

cis-yogesh commented 10 years ago

Hello All,

I have written code according to documentation. My setting file is CRON_CLASSES = [ "cronapp.cron.MyCronJob", "django_cron.cron.FailedRunsNotificationCronJob" ] INSTALLED_APPS = ( 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.sites', 'django.contrib.messages', 'django.contrib.staticfiles', 'django_cron', )

My cron.py file is within my app directory from django_cron import CronJobBase, Schedule class MyCronJob(CronJobBase): RUN_EVERY_MINS = 10 schedule = Schedule(run_every_mins=RUN_EVERY_MINS) code = 'cronapp.MyCronJob' # a unique code

def do(self):
    f = open('/home/user/Desktop/crontest/yogesh.txt','w')
    f.write(str(datetime.now()))
    f.close()

and first time when i am going to run command "python manage.py runcrons" code is executed. after that this code not executed every 2 min. I am going to setup cron job first time can you please let me know. what i am doing wrong. Regards Yogesh D

craiglabenz commented 10 years ago

You're fundamentally misunderstanding how this library works.

runcrons is a command that, when executed once, will loop over your CRON_CLASSES list and determine if each cron needs to be run once, right now.

You need to invoke runcrons yourself via the actual crontab.

I do that in my projects with this crontab:

* * * * * /path/to/crons.sh >> /var/logs/cronjobs/crons.log 3 >> /var/logs/cronjobs/cron_errors.log

Where cron.sh has open permissions and looks like this:

#! /bin/bash
source /path/to/virtualenvs/mysite/bin/activate
python /var/www/mysite/manage.py runcrons
deactivate

Be sure to activate some type of caching engine, as that is what django_crons uses to enforce the ALLOW_PARALLEL_RUNS setting value. I use simple DB caching for this.

cis-yogesh commented 10 years ago

Thanks @craiglabenz , I am gone according to your instructional and My crones are start running .