Conversion_Kitchen_Code/kitchen_counter/lpp/cron.py

47 lines
2.3 KiB
Python
Raw Permalink Normal View History

2024-04-27 09:33:09 +00:00
from django.utils import timezone
from .models import LPPTASKDatabase
from .views import reassign_task
from auto_email.views import sendmail
def check_deadlines_for_lpp():
try:
print("Cron Job for lpp task deadlines")
tasks = LPPTASKDatabase.objects.all()
for task in tasks:
if task.assignedlpp_action:
if task.deadlinetolpp_action:
if (task.deadlinetolpp_action - timezone.now()).total_seconds() < 0:
to = task.assignedlpp_action.lpp_email
key_value = {
"User": task.assignedlpp_action.user_id.username
}
sendmail(to_email=[to], email_code="PP7", key_value=key_value)
if len(list(task.eligiblelpp_action.all())) > 0:
reassign_task(task.task_id, "action", "eligible")
else:
reassign_task(task.task_id, "action", "noneligible")
elif task.assignedlpp_dialogue:
if task.deadlinetolpp_dialogue:
# print(task.deadlinetolpp_dialogue - timezone.now())
if (task.deadlinetolpp_dialogue - timezone.now()).total_seconds() < 0:
to = task.assignedlpp_dialogue.lpp_email
key_value = {
"User": task.assignedlpp_dialogue.user_id.username
}
sendmail(to_email=[to], email_code="PP7", key_value=key_value)
if task.translated_script:
if len(list(task.eligiblelpp_dialogue.all())) > 0:
reassign_task(task.task_id, "dialogue", "eligible")
else:
reassign_task(task.task_id, "dialogue", "noneligible")
# else:
# if len(list(task.eligiblelpp_dialogue.all())) > 0:
# reassign_task(task.task_id, "subtitle", "eligible")
# else:
# # reassign_task(task.task_id, "subtitle", "noneligible")
except Exception as e:
print("Exception of cron lpp deadlines is:", e)