mirror of
https://github.com/HamzaSha1/zod-backend.git
synced 2025-11-27 17:14:55 +00:00
changed notification method, added celery task to notify expiring task
This commit is contained in:
@ -1,6 +1,8 @@
|
||||
"""
|
||||
web_admin tasks file
|
||||
"""
|
||||
import datetime
|
||||
|
||||
# third party imports
|
||||
from celery import shared_task
|
||||
from templated_email import send_templated_mail
|
||||
@ -8,6 +10,12 @@ from templated_email import send_templated_mail
|
||||
# django imports
|
||||
from django.conf import settings
|
||||
|
||||
# local imports
|
||||
from base.constants import PENDING, IN_PROGRESS, JUNIOR
|
||||
from guardian.models import JuniorTask
|
||||
from notifications.constants import PENDING_TASK_EXPIRING, IN_PROGRESS_TASK_EXPIRING
|
||||
from notifications.utils import send_notification
|
||||
|
||||
|
||||
@shared_task
|
||||
def send_email_otp(email, verification_code):
|
||||
@ -27,3 +35,24 @@ def send_email_otp(email, verification_code):
|
||||
}
|
||||
)
|
||||
return True
|
||||
|
||||
|
||||
@shared_task()
|
||||
def notify_task_expiry():
|
||||
"""
|
||||
task to send notification for those task which expiring soon
|
||||
:return:
|
||||
"""
|
||||
all_pending_tasks = JuniorTask.objects.filter(
|
||||
task_status__in=[PENDING, IN_PROGRESS],
|
||||
due_date__range=[datetime.datetime.now().date(),
|
||||
(datetime.datetime.now().date() + datetime.timedelta(days=1))])
|
||||
if pending_tasks := all_pending_tasks.filter(task_status=PENDING):
|
||||
for task in pending_tasks:
|
||||
send_notification(PENDING_TASK_EXPIRING, None, None, task.junior.auth.id,
|
||||
{'task_id': task.id})
|
||||
if in_progress_tasks := all_pending_tasks.filter(task_status=IN_PROGRESS):
|
||||
for task in in_progress_tasks:
|
||||
send_notification(IN_PROGRESS_TASK_EXPIRING, task.junior.auth.id, JUNIOR, task.guardian.user.id,
|
||||
{'task_id': task.id})
|
||||
return True
|
||||
|
||||
Reference in New Issue
Block a user