Backend Draft
This commit is contained in:
23
backend/dashboard/tasks.py
Normal file
23
backend/dashboard/tasks.py
Normal file
@@ -0,0 +1,23 @@
|
||||
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
|
||||
Reference in New Issue
Block a user