Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Celery task params #53

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions sendsms/backends/celery.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,17 @@

In settings.py


SENDSMS_BACKEND = 'sendsms.backends.celery.SmsBackend'
CELERY_SENDSMS_BACKEND = 'actual.backend.to.use.SmsBackend'

# optional, celery task parameters
CELERY_SENDSMS_TASK_CONFIG = {}

"""
from __future__ import absolute_import

from django.conf import settings
from django.core.exceptions import ImproperlyConfigured
from django.utils.six import string_types

from celery import shared_task

Expand All @@ -33,8 +34,21 @@
if not CELERY_SENDSMS_BACKEND:
raise ImproperlyConfigured("Set CELERY_SENDSMS_BACKEND")

TASK_CONFIG = {"name": "sendsms_send_messages", "ignore_result": True}

CELERY_SENDSMS_TASK_CONFIG = getattr(settings, "CELERY_SENDSMS_TASK_CONFIG", None)

if CELERY_SENDSMS_TASK_CONFIG:
TASK_CONFIG.update(settings.CELERY_SENDSMS_TASK_CONFIG)

# import base if string to allow a base celery task
if "base" in TASK_CONFIG and isinstance(TASK_CONFIG["base"], string_types):
from django.utils.module_loading import import_string

TASK_CONFIG["base"] = import_string(TASK_CONFIG["base"])


@shared_task
@shared_task(**TASK_CONFIG)
def send_messages(messages):
connection = get_connection(CELERY_SENDSMS_BACKEND)
connection.send_messages(messages)
Expand Down