mirror of
https://github.com/jazzband/django-celery-monitor.git
synced 2026-03-16 22:00:24 +00:00
Stop shipping our own version of django.utils.timezone.now.
This commit is contained in:
parent
4526b8c8b2
commit
e36dc66467
4 changed files with 9 additions and 18 deletions
|
|
@ -4,7 +4,7 @@ from __future__ import absolute_import, unicode_literals
|
|||
from datetime import datetime
|
||||
|
||||
from django.utils.translation import ungettext, ugettext as _
|
||||
from .utils import now
|
||||
from django.utils.timezone import now
|
||||
|
||||
|
||||
def pluralize_year(n):
|
||||
|
|
|
|||
|
|
@ -3,8 +3,8 @@ from __future__ import absolute_import, unicode_literals
|
|||
|
||||
from celery.utils.time import maybe_timedelta
|
||||
from django.db import connections, models, router, transaction
|
||||
from django.utils import timezone
|
||||
|
||||
from .utils import now
|
||||
|
||||
|
||||
class TaskStateManager(models.Manager):
|
||||
|
|
@ -18,10 +18,12 @@ class TaskStateManager(models.Manager):
|
|||
"""Return all active task states."""
|
||||
return self.filter(hidden=False)
|
||||
|
||||
def expired(self, states, expires, nowfun=now):
|
||||
def expired(self, states, expires):
|
||||
"""Return all expired task states."""
|
||||
return self.filter(state__in=states,
|
||||
tstamp__lte=nowfun() - maybe_timedelta(expires))
|
||||
return self.filter(
|
||||
state__in=states,
|
||||
tstamp__lte=timezone.now() - maybe_timedelta(expires),
|
||||
)
|
||||
|
||||
def expire_by_states(self, states, expires):
|
||||
"""Expire task with one of the given states."""
|
||||
|
|
|
|||
|
|
@ -8,17 +8,6 @@ from datetime import datetime
|
|||
from django.conf import settings
|
||||
from django.utils import timezone
|
||||
|
||||
# see Issue celery/django-celery#222
|
||||
now_localtime = getattr(timezone, 'template_localtime', timezone.localtime)
|
||||
|
||||
|
||||
def now():
|
||||
"""Return the current date and time."""
|
||||
if getattr(settings, 'USE_TZ', False):
|
||||
return now_localtime(timezone.now())
|
||||
else:
|
||||
return timezone.now()
|
||||
|
||||
|
||||
def make_aware(value):
|
||||
"""Make the given datetime aware of a timezone."""
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ from django.test.utils import override_settings
|
|||
from django.utils import timezone
|
||||
|
||||
from django_celery_monitor import camera, models
|
||||
from django_celery_monitor.utils import make_aware, now
|
||||
from django_celery_monitor.utils import make_aware
|
||||
|
||||
|
||||
_ids = count(0)
|
||||
|
|
@ -90,7 +90,7 @@ class test_Camera:
|
|||
assert mt.name == task.name
|
||||
assert str(mt)
|
||||
assert repr(mt)
|
||||
mt.eta = now()
|
||||
mt.eta = timezone.now()
|
||||
assert 'eta' in str(mt)
|
||||
assert mt in models.TaskState.objects.active()
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue