Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Timezone errors() #9

Merged
merged 2 commits into from

2 participants

Mickey Cheong Dariusz Fryta
Mickey Cheong

Hi,

There is a need to update the code to use django.utils.timezone.now().

Cheers,
Mickey

Dariusz Fryta dfryta merged commit 39a6233 into from
Dariusz Fryta
Owner

This caused problem in django < 1.4. Timezone module is new in django 1.4.

Dariusz Fryta
Owner

I have added missing timezone module from django 1.4. It's working now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 28, 2012
  1. Update CronJobManager to timezone-aware now()

    mickeyckm authored
  2. Update runcrons Command() to timezone.now()

    mickeyckm authored
This page is out of date. Refresh to see the latest.
7 django_cron/__init__.py
View
@@ -1,5 +1,6 @@
import logging
from datetime import datetime, timedelta
+from django.utils import timezone
import traceback
from django_cron.models import CronJobLog
@@ -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
@@ -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:
cron_job.do()
@@ -60,5 +61,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 django_cron/management/commands/runcrons.py
View
@@ -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
@@ -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:
Something went wrong with that request. Please try again.