From f8b12681e8a1e96c4e609412e9c6b04511501d64 Mon Sep 17 00:00:00 2001 From: DEKHTIARJonathan Date: Thu, 5 Apr 2018 16:00:45 +0200 Subject: [PATCH] Fix attempt of https://github.com/jezdez/django-celery-monitor/issues/55 --- django_celery_monitor/managers.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/django_celery_monitor/managers.py b/django_celery_monitor/managers.py index 2d21d5a..fa20900 100644 --- a/django_celery_monitor/managers.py +++ b/django_celery_monitor/managers.py @@ -7,7 +7,8 @@ from celery.utils.time import maybe_timedelta from django.db import models, router, transaction -from .utils import Now +#from .utils import Now +from django.utils import timezone class ExtendedQuerySet(models.QuerySet): @@ -47,7 +48,8 @@ class WorkerStateQuerySet(ExtendedQuerySet): def update_heartbeat(self, hostname, heartbeat, update_freq): with transaction.atomic(): # check if there was an update in the last n seconds? - interval = Now() - timedelta(seconds=update_freq) + #interval = Now() - timedelta(seconds=update_freq) + interval = timezone.now() - timedelta(seconds=update_freq) recent_worker_updates = self.filter( hostname=hostname, last_update__gte=interval, @@ -74,8 +76,9 @@ def active(self): def expired(self, states, expires): """Return all expired task states.""" return self.filter( - state__in=states, - tstamp__lte=Now() - maybe_timedelta(expires), + state__in = states, + #tstamp__lte = Now() - maybe_timedelta(expires), + tstamp__lte = timezone.now() - maybe_timedelta(expires), ) def expire_by_states(self, states, expires):