Permalink
Browse files

Discard the seconds to prevent drift. Thanks to Josh Cartmell

  • Loading branch information...
1 parent 21078d6 commit 01b4f8ccc83f8719d029d56659253ffa65166ab1 @andybak andybak committed Apr 6, 2012
Showing with 7 additions and 1 deletion.
  1. +7 −1 django_cron/base.py
View
@@ -159,7 +159,13 @@ def execute(self, start_timer=True, registering=False):
jobs = models.Job.objects.all()
for job in jobs:
if job.queued:
- if (datetime.now() - job.last_run) > timedelta(minutes=job.run_frequency):
+
+ # Discard the seconds to prevent drift. Thanks to Josh Cartmell
+ now = datetime.now()
+ now = datetime(now.year, now.month, now.day, now.hour, now.minute)
+ last_run = datetime(job.last_run.year, job.last_run.month, job.last_run.day, job.last_run.hour, job.last_run.minute)
+
+ if (now - last_run) >= timedelta(minutes=job.run_frequency):
inst = cPickle.loads(str(job.instance))
args = cPickle.loads(str(job.args))
kwargs = cPickle.loads(str(job.kwargs))

0 comments on commit 01b4f8c

Please sign in to comment.