Skip to content

Commit

Permalink
use from celery import shared_task instead of djcelery_transactions
Browse files Browse the repository at this point in the history
  • Loading branch information
jedie committed Feb 5, 2018
1 parent c786d93 commit b863fd8
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 11 deletions.
2 changes: 1 addition & 1 deletion README.creole
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ to:
== history

* *dev* - [[https://github.com/jedie/django-tools/compare/v0.38.6...master|compare v0.38.6...master]]
** (no changes yet)
** send mail: use from celery import shared_task instead of djcelery_transactions
* v0.38.7 - 15.01.2018 - [[https://github.com/jedie/django-tools/compare/v0.38.5...v0.38.6|compare v0.38.5...v0.38.6]]
** Add missing arguments (like "attachments", "cc" etc.) to {{{django_tools.mail.send_mail.SendMailCelery}}}
* v0.38.6 - 10.01.2018 - [[https://github.com/jedie/django-tools/compare/v0.38.4...v0.38.5|compare v0.38.4...v0.38.5]]
Expand Down
17 changes: 8 additions & 9 deletions django_tools/mail/celery_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
mail util
~~~~~~~~~
:copyleft: 2017 by the django-tools team, see AUTHORS for more details.
:copyleft: 2017-2018 by the django-tools team, see AUTHORS for more details.
:license: GNU GPL v3 or above, see LICENSE for more details.
"""

Expand All @@ -19,32 +19,31 @@
log = logging.getLogger(__name__)


# https://github.com/fellowshipofone/django-celery-transactions
try:
from djcelery_transactions import task
from celery import shared_task
except ImportError as err:
CELERY_TRANSACTIONS_IMPORT_ERROR = err
CELERY_IMPORT_ERROR = err

from functools import wraps

def task(*task_args, **task_kwargs):
def shared_task(*task_args, **task_kwargs):
def task_decorator(func):
@wraps(func)
def func_wrapper(*args, **kwargs):
log.error(
"django-celery-transactions not available: %s",
CELERY_TRANSACTIONS_IMPORT_ERROR
"celery not available: %s",
CELERY_IMPORT_ERROR
)
return func(*args, **kwargs)
return func_wrapper
return task_decorator


@task(name='mail:send_mail')
@shared_task(name='mail:send_mail')
def send_mail(subject, message, from_email, recipient_list):
do_send_mail(subject, message, from_email, recipient_list)


@task(name=settings.SEND_MAIL_CELERY_TASK_NAME)
@shared_task(name=settings.SEND_MAIL_CELERY_TASK_NAME)
def send_mail_celery_task(msg):
msg.send()
1 change: 0 additions & 1 deletion requirements-test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,3 @@ django-filer
pytest-django
pytest-cov
celery
django-celery-transactions

0 comments on commit b863fd8

Please sign in to comment.