24 lines
798 B
Python
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
|