Skip to content

Commit

Permalink
Merge pull request Tivix#9 from mickeyckm/master
Browse files Browse the repository at this point in the history
Timezone errors()
  • Loading branch information
dfryta committed Jul 18, 2012
2 parents dd3e12e + 2e4a934 commit 39a6233
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
7 changes: 4 additions & 3 deletions django_cron/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import logging
from datetime import datetime, timedelta
from django.utils import timezone
import traceback

from django_cron.models import CronJobLog
Expand Down Expand Up @@ -36,7 +37,7 @@ def __should_run_now(self, cron_job, force=False):
qset = CronJobLog.objects.filter(code=cron_job.code, is_success=True).order_by('-start_time')
if qset:
previously_ran_successful_cron = qset[0]
if datetime.now() < previously_ran_successful_cron.start_time + timedelta(minutes=cron_job.schedule.run_every_mins):
if timezone.now() < previously_ran_successful_cron.start_time + timedelta(minutes=cron_job.schedule.run_every_mins):
return False

return True
Expand All @@ -51,7 +52,7 @@ def run(self, cron_job, force=False):

if CronJobManager.__should_run_now(cron_job, force):
logging.info("Running cron: %s" % cron_job)
cron_log = CronJobLog(code=cron_job.code, start_time=datetime.now())
cron_log = CronJobLog(code=cron_job.code, start_time=timezone.now())

try:
msg = cron_job.do()
Expand All @@ -61,5 +62,5 @@ def run(self, cron_job, force=False):
cron_log.is_success = False
cron_log.message = traceback.format_exc()[-1000:]

cron_log.end_time = datetime.now()
cron_log.end_time = timezone.now()
cron_log.save()
4 changes: 2 additions & 2 deletions django_cron/management/commands/runcrons.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from django.core.management.base import BaseCommand
from django.conf import settings
from django.core.cache import cache

from django.utils import timezone
from django_cron import CronJobManager

from datetime import datetime
Expand Down Expand Up @@ -34,7 +34,7 @@ def handle(self, *args, **options):
timeout = settings.DJANGO_CRON_LOCK_TIME
except:
pass
cache.set(cron_class.__name__, datetime.now(), timeout)
cache.set(cron_class.__name__, timezone.now(), timeout)
CronJobManager.run(instance, options['force'])
cache.delete(cron_class.__name__)
else:
Expand Down

0 comments on commit 39a6233

Please sign in to comment.