Skip to content
Snippets Groups Projects
Verified Commit bb3295e1 authored by Jonathan Weth's avatar Jonathan Weth :keyboard:
Browse files

Merge branch 'master' of edugit.org:AlekSIS/official/AlekSIS

parents 603df38d 0c43ebe4
No related branches found
No related tags found
1 merge request!210[Docker] Add celery as an extra to Dockerfile
Pipeline #1270 failed
......@@ -14,8 +14,8 @@ from phonenumber_field.modelfields import PhoneNumberField
from polymorphic.models import PolymorphicModel
from .mixins import ExtensibleModel, PureDjangoModel
from .tasks import send_notification
from .util.core_helpers import now_tomorrow
from .util.notifications import send_notification
from .util.model_helpers import ICONS
from constance import config
......@@ -276,7 +276,8 @@ class Notification(ExtensibleModel):
return str(self.title)
def save(self, **kwargs):
send_notification(self)
if not self.sent:
send_notification(self.pk, resend=True)
self.sent = True
super().save(**kwargs)
......
......@@ -436,7 +436,7 @@ if _settings.get("twilio.sid", None):
if _settings.get("celery.enabled", False):
INSTALLED_APPS += ("django_celery_beat", "django_celery_results")
CELERY_BROKER_URL = "redis://localhost"
CELERY_BROKER_URL = _settings.get("celery.broker", "redis://localhost")
CELERY_RESULT_BACKEND = "django-db"
CELERY_CACHE_BACKEND = "django-cache"
CELERY_BEAT_SCHEDULER = "django_celery_beat.schedulers:DatabaseScheduler"
......
from .util.core_helpers import celery_optional
from .util.notifications import send_notification as _send_notification
@celery_optional
def send_notification(notification: int, resend: bool = False) -> None:
_send_notification(notification, resend)
......@@ -116,11 +116,12 @@ def celery_optional(orig: Callable) -> Callable:
and it is executed synchronously.
"""
if hasattr(settings, "CELERY_RESULT_BACKEND"):
from ..celery import app # noqa
task = app.task(orig)
def wrapped(*args, **kwargs):
if hasattr(settings, "CELERY_RESULT_BACKEND"):
from ..celery import app # noqa
task = app.task(orig)
task.delay(*args, **kwargs)
else:
orig(*args, **kwargs)
......
......@@ -68,7 +68,6 @@ _CHANNELS_MAP = {
}
@celery_optional
def send_notification(notification: Union[int, "Notification"], resend: bool = False) -> None:
""" Send a notification through enabled channels.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment