Skip to content

Commit

Permalink
Merge pull request #5 from opapy/feature/celery31
Browse files Browse the repository at this point in the history
support celery 3.1
  • Loading branch information
opapy authored Nov 2, 2016
2 parents 4710848 + c37d448 commit 7ef2b37
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 50 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[![Build Status](https://travis-ci.org/beproud/bpmailer.svg?branch=master)](https://travis-ci.org/beproud/bpmailer)

# Requirements

* Python (2.6, 2.7)
* Celery (2.2, 3.0, 3.1)
* Django (1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8)
* django-jsonfield (0.8, 0.9)

django-jsonfield > 0.9.0 does not support django 1.2 and 1.3
71 changes: 39 additions & 32 deletions beproud/django/notify/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,42 @@
from django.core.exceptions import ImproperlyConfigured
from django.conf import settings

if 'djcelery' not in settings.INSTALLED_APPS:
raise ImproperlyConfigured("You must add djcelery to INSTALLED_APPS to use "
"the asyncronous task queue")

try:
from celery.task import Task
from celery.registry import tasks

from beproud.django.notify import notify_now

class Notify(Task):

def run(self, targets, notify_type, extra_data={}, include_media=None, exclude_media=[],
max_retries=3, retry_countdown=10, **kwargs):
try:
return notify_now(
targets,
notify_type,
extra_data=extra_data,
include_media=include_media,
exclude_media=exclude_media,
)
except Exception, e:
return self.retry(
exc=e,
countdown=retry_countdown,
max_retries=max_retries,
)
tasks.register(Notify)

except ImportError:
raise ImproperlyConfigured("You must install celery to use the asyncronous task queue")
import celery
from celery.task import Task
from celery.registry import tasks

if celery.VERSION < (3, 1):
try:
import djcelery # NOQA
except ImportError:
from django.core.exceptions import ImproperlyConfigured
raise ImproperlyConfigured("when used celery<3.1, djcelery is required!")

if 'djcelery' not in settings.INSTALLED_APPS:
from django.core.exceptions import ImproperlyConfigured
raise ImproperlyConfigured("djcelery not in INSTALLED_APPS!")

from beproud.django.notify import notify_now


class Notify(Task):

def run(self, targets, notify_type, extra_data={}, include_media=None, exclude_media=[],
max_retries=3, retry_countdown=10, **kwargs):
try:
return notify_now(
targets,
notify_type,
extra_data=extra_data,
include_media=include_media,
exclude_media=exclude_media,
)
except Exception, e:
return self.retry(
exc=e,
countdown=retry_countdown,
max_retries=max_retries,
)


tasks.register(Notify)
5 changes: 2 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
description='Notification routing for Django',
author='Ian Lewis',
author_email='ian@beproud.jp',
url='https://project.beproud.jp/hg/bpnotify/',
url='https://github.com/beproud/bpnotify/',
classifiers=[
'Development Status :: 3 - Alpha',
'Environment :: Plugins',
Expand All @@ -28,9 +28,8 @@
'django-jsonfield>=0.8.7',
],
tests_require=[
'mock>=0.7.2',
'celery>=2.2.7',
'django-celery>=2.2.4',
'mock>=0.7.2',
],
zip_safe=False,
)
11 changes: 8 additions & 3 deletions tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
import sys
import django

# Make sure djcelery is imported before celery
import djcelery # NOQA

BASE_PATH = os.path.dirname(__file__)

Expand All @@ -22,7 +20,6 @@ def main():
'django.contrib.auth',
'django.contrib.contenttypes',
'beproud.django.notify',
'djcelery',
)

global_settings.DATABASES = {
Expand Down Expand Up @@ -58,6 +55,14 @@ def main():
}
global_settings.BPNOTIFY_SETTINGS_STORAGE = 'beproud.django.notify.storage.db.DBStorage'

import celery
if celery.VERSION >= (3, 1):
app = celery.Celery()
app.config_from_object('django.conf:settings')
app.autodiscover_tasks(lambda: global_settings.INSTALLED_APPS)
else:
global_settings.INSTALLED_APPS += ('djcelery',)

if django.VERSION > (1, 7):
django.setup()

Expand Down
45 changes: 33 additions & 12 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,12 @@ envlist = django14-py27,
django16-py27,
django17-py27,
django18-py27
django18-celery22-py27
django18-celery30-py27

[testenv]
commands=python setup.py test

[base]
deps =
mock==1.0.1
celery==2.2.7
kombu==1.1.6
django-celery==2.2.4

[py27]
basepython=python2.7

Expand All @@ -24,72 +19,98 @@ deps=
Django>=1.2,<1.3
# django-jsonfield > 0.9.0 does not support django 1.2
django-jsonfield==0.8.12
celery>=3.1,<4.0

[django13]
deps=
Django>=1.3,<1.4
# django-jsonfield > 0.9.0 does not support django 1.3
django-jsonfield==0.8.12
celery>=3.1,<4.0

[django14]
deps=
Django>=1.4,<1.5
django-jsonfield==0.9.13
celery>=3.1,<4.0

[django15]
deps=
Django>=1.5,<1.6
django-jsonfield==0.9.13
celery>=3.1,<4.0

[django16]
deps=
Django>=1.6,<1.7
django-jsonfield==0.9.13
celery>=3.1,<4.0

[django17]
deps=
Django>=1.7,<1.8
django-jsonfield==0.9.13
celery>=3.1,<4.0

[django18]
deps=
Django>=1.8,<1.9
django-jsonfield==0.9.13
celery>=3.1,<4.0

[django18-celery22]
deps=
Django>=1.8,<1.9
django-jsonfield==0.9.13
celery>=2.2,<3.0
django-celery>=2.2,<3.0

[django18-celery30]
deps=
Django>=1.8,<1.9
django-jsonfield==0.9.13
celery>=3.0,<3.1
django-celery>=2.2,<3.0

# Django 1.4

[testenv:django14-py27]
basepython={[py27]basepython}
deps=
{[django14]deps}
{[base]deps}

# Django 1.5

[testenv:django15-py27]
basepython={[py27]basepython}
deps=
{[django15]deps}
{[base]deps}

# Django 1.6

[testenv:django16-py27]
basepython={[py27]basepython}
deps=
{[django16]deps}
{[base]deps}

# Django 1.7

[testenv:django17-py27]
basepython={[py27]basepython}
deps=
{[django17]deps}
{[base]deps}

[testenv:django18-py27]
basepython={[py27]basepython}
deps=
{[django18]deps}
{[base]deps}

[testenv:django18-celery22-py27]
basepython={[py27]basepython}
deps=
{[django18-celery22]deps}

[testenv:django18-celery30-py27]
basepython={[py27]basepython}
deps=
{[django18-celery30]deps}

0 comments on commit 7ef2b37

Please sign in to comment.