Skip to content

Commit d231521

Browse files
committed
Compatibility with Celery 3.2a1
1 parent 98feca0 commit d231521

File tree

6 files changed

+19
-17
lines changed

6 files changed

+19
-17
lines changed

djcelery/backends/cache.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
from django.core.cache import cache, get_cache
99

1010
from celery import current_app
11-
from celery.utils.timeutils import timedelta_seconds
1211
from celery.backends.base import KeyValueStoreBackend
1312

1413
# CELERY_CACHE_BACKEND overrides the django-global(tm) backend settings.
@@ -55,7 +54,7 @@ def __init__(self, *args, **kwargs):
5554
expires = kwargs.get('expires',
5655
current_app.conf.CELERY_TASK_RESULT_EXPIRES)
5756
if isinstance(expires, timedelta):
58-
expires = int(timedelta_seconds(expires))
57+
expires = int(max(expires.total_seconds(), 0))
5958
self.expires = expires
6059

6160
def get(self, key):

djcelery/models.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
from celery import schedules
1212
from celery import states
1313
from celery.events.state import heartbeat_expires
14-
from celery.utils.timeutils import timedelta_seconds
1514

1615
from . import managers
1716
from .picklefield import PickledObjectField
@@ -104,7 +103,7 @@ def schedule(self):
104103

105104
@classmethod
106105
def from_schedule(cls, schedule, period='seconds'):
107-
every = timedelta_seconds(schedule.run_every)
106+
every = max(schedule.run_every.total_seconds(), 0)
108107
try:
109108
return cls.objects.get(every=every, period=period)
110109
except cls.DoesNotExist:

djcelery/tests/test_schedulers.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
from celery.five import monotonic
77
from celery.schedules import schedule, crontab
8-
from celery.utils.timeutils import timedelta_seconds
98

109
from djcelery import schedulers
1110
from djcelery import celery
@@ -245,7 +244,7 @@ def test_PeriodicTask_unicode_crontab(self):
245244
def test_PeriodicTask_schedule_property(self):
246245
p1 = create_model_interval(schedule(timedelta(seconds=10)))
247246
s1 = p1.schedule
248-
self.assertEqual(timedelta_seconds(s1.run_every), 10)
247+
self.assertEqual(s1.run_every.total_seconds(), 10)
249248

250249
p2 = create_model_crontab(crontab(hour='4, 5',
251250
minute='10,20,30',

djcelery/tests/test_views.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -186,9 +186,9 @@ def test_retry(self):
186186

187187
class test_task_is_successful(ViewTestCase):
188188

189-
def assertStatusForIs(self, status, outcome):
189+
def assertStatusForIs(self, status, outcome, result=None):
190190
uuid = gen_unique_id()
191-
result = gen_unique_id()
191+
result = result or gen_unique_id()
192192
current_app.backend.store_result(uuid, result, status)
193193
json = self.client.get(task_is_successful(task_id=uuid))
194194
self.assertJSONEqual(json, {'task': {'id': uuid,
@@ -201,7 +201,7 @@ def test_pending(self):
201201
self.assertStatusForIs(states.PENDING, False)
202202

203203
def test_failure(self):
204-
self.assertStatusForIs(states.FAILURE, False)
204+
self.assertStatusForIs(states.FAILURE, False, KeyError('foo'))
205205

206206
def test_retry(self):
207-
self.assertStatusForIs(states.RETRY, False)
207+
self.assertStatusForIs(states.RETRY, False, KeyError('foo'))

djcelery/views.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@
77
from anyjson import serialize
88

99
from celery import states
10+
from celery.five import keys, items
1011
from celery.registry import tasks
1112
from celery.result import AsyncResult
12-
from celery.utils import get_full_cls_name, kwdict
13+
from celery.utils import get_full_cls_name
1314
from celery.utils.encoding import safe_repr
1415

1516
# Ensure built-in tasks are loaded for task_list view
@@ -31,10 +32,11 @@ def task_view(task):
3132
"""
3233

3334
def _applier(request, **options):
34-
kwargs = kwdict(request.method == 'POST' and
35-
request.POST or request.GET)
35+
kwargs = request.POST if request.method == 'POST' else request.GET
3636
# no multivalue
37-
kwargs = dict(((k, v) for k, v in kwargs.iteritems()), **options)
37+
kwargs = {k: v for k, v in items(kwargs)}
38+
if options:
39+
kwargs.update(options)
3840
result = task.apply_async(kwargs=kwargs)
3941
return JsonResponse({'ok': 'true', 'task_id': result.task_id})
4042

@@ -67,7 +69,7 @@ def task_status(request, task_id):
6769
"""Returns task status and result in JSON format."""
6870
result = AsyncResult(task_id)
6971
state, retval = result.state, result.result
70-
response_data = dict(id=task_id, status=state, result=retval)
72+
response_data = {'id': task_id, 'status': state, 'result': retval}
7173
if state in states.EXCEPTION_STATES:
7274
traceback = result.traceback
7375
response_data.update({'result': safe_repr(retval),
@@ -78,8 +80,7 @@ def task_status(request, task_id):
7880

7981
def registered_tasks(request):
8082
"""View returning all defined tasks as a JSON object."""
81-
return JsonResponse({'regular': tasks.regular().keys(),
82-
'periodic': tasks.periodic().keys()})
83+
return JsonResponse({'regular': list(keys(tasks)), 'periodic': ''})
8384

8485

8586
def task_webhook(fun):

tests/settings.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@
5959

6060
CELERY_QUEUES = {'testcelery': {'binding_key': 'testcelery'}}
6161

62+
CELERY_ACCEPT_CONTENT = ['pickle', 'json']
63+
CELERY_TASK_SERIALIZER = 'pickle'
64+
CELERY_RESULT_SERIALIZER = 'pickle'
65+
6266
MANAGERS = ADMINS
6367

6468
DATABASES = {

0 commit comments

Comments
 (0)