From fdbbc25a2d43021b93eebcc94e4747b9a490d3d6 Mon Sep 17 00:00:00 2001 From: Lev Lybin Date: Mon, 7 Oct 2019 20:01:26 +0700 Subject: [PATCH] celery task params --- sendsms/backends/celery.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/sendsms/backends/celery.py b/sendsms/backends/celery.py index c36bc96..31eae8b 100644 --- a/sendsms/backends/celery.py +++ b/sendsms/backends/celery.py @@ -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 @@ -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)