Skip to content

Commit

Permalink
Fix celery task integration
Browse files Browse the repository at this point in the history
  • Loading branch information
saulshanabrook committed Dec 26, 2015
1 parent 111c21f commit 11ec7e1
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 5 deletions.
1 change: 1 addition & 0 deletions docs/source/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Changelog
=========

* :bug:`-` Fixed Celery task defination.
* :release:`1.3.2 <2015.12.22>`
* :support:`26` Removed lambdas in docs for model.
* :bug:`-` Removed extranious `print` debugging.
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"six",
"Pillow",
'clint',
'dill',
],
zip_safe=False, # so that django finds management commands,
classifiers=[
Expand Down
16 changes: 11 additions & 5 deletions simpleimages/callers.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
from __future__ import absolute_import

import dill


def default(function, *args, **kwargs):
'''
Calls ``function`` with any passed in ``args`` and ``kwargs.
Expand All @@ -14,9 +19,10 @@ def _no_action(function, *args, **kwargs):

def celery(function, *args, **kwargs):
'''
Calls ``function`` asynchronously by creating a
`shared-task <http://docs.celeryproject.org/en/latest/django/first-steps-with-django.html#using-the-shared-task-decorator>`_
with celery.
Calls ``function`` asynchronously by creating a pickling it and
calling it in a task.
'''
from celery import shared_task
shared_task(function).delay(*args, **kwargs)
from .tasks import dill_callable

dilled_function = dill.dumps(function)
dill_callable.delay(dilled_function, *args, **kwargs)
8 changes: 8 additions & 0 deletions simpleimages/tasks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from celery import shared_task
import dill


@shared_task
def dill_callable(dilled_callable, *args, **kwargs):
callable = dill.loads(dilled_callable)
return callable(*args, **kwargs)

0 comments on commit 11ec7e1

Please sign in to comment.