Files
MTCBD/backend/dashboard/tasks.py
2026-02-23 20:31:53 +05:30

24 lines
798 B
Python

from celery import shared_task
from django.contrib.auth import get_user_model
from dashboard.models import Notification
from tenants.models import Tenant
User = get_user_model()
@shared_task
def send_notification_email_async(notification_id):
"""
Example Celery task to asynchronously send an email
when a new notification is generated.
"""
try:
notification = Notification.objects.get(id=notification_id)
user = notification.user
# In a real scenario, this would use django.core.mail.send_mail
print(f"ASYNC TASK: Sending email to {user.email} regarding: {notification.title}")
return True
except Notification.DoesNotExist:
print(f"ASYNC TASK ERR: Notification {notification_id} not found.")
return False