Wednesday, November 16, 2016

django-cron running command constantly instead of on schedule

Hi python-lovers,

Today I've experienced weird problem with django-cron==0.4.6 (and django 1.9.5). And I thought it would be useful to share with you.

I had job class which is defined like this:
class MyJob(CronJobBase):
   RUN_EVERY_MINS = 60 * 24    
   schedule = Schedule(run_every_mins=RUN_EVERY_MINS)
   code = 'myapp.myjob'    
   def do(self):
       do_some_task()

Theoretically it should be run once a day. But in practice, every time when I was trying to run "python manage.py runcrons", do_some_task() had been called.

I tried everything, including downgrading django-cron. But the actual problem was that do_some_task had an exception in it. Unfortunately it was not reported in any way. No logs, no warnings were spit by django-cron.

The conclusion

If there is any exception in your job, it will be re-run unlimited number of times by django-cron, ignoring your schedule. Beware of that.

No comments:

Post a Comment