From cc329050da7bebc8769985234b73f913c0b0ed9d Mon Sep 17 00:00:00 2001 From: Jan Timpe Date: Fri, 20 Sep 2024 12:25:13 -0400 Subject: [PATCH] convert to celery task --- .../data_files/management/__init__.py | 0 .../management/commands/__init__.py | 0 .../find_pending_submissions.py => tasks.py} | 23 +++++++++---------- tdrs-backend/tdpservice/settings/common.py | 4 ++++ 4 files changed, 15 insertions(+), 12 deletions(-) delete mode 100644 tdrs-backend/tdpservice/data_files/management/__init__.py delete mode 100644 tdrs-backend/tdpservice/data_files/management/commands/__init__.py rename tdrs-backend/tdpservice/data_files/{management/commands/find_pending_submissions.py => tasks.py} (70%) diff --git a/tdrs-backend/tdpservice/data_files/management/__init__.py b/tdrs-backend/tdpservice/data_files/management/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/tdrs-backend/tdpservice/data_files/management/commands/__init__.py b/tdrs-backend/tdpservice/data_files/management/commands/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/tdrs-backend/tdpservice/data_files/management/commands/find_pending_submissions.py b/tdrs-backend/tdpservice/data_files/tasks.py similarity index 70% rename from tdrs-backend/tdpservice/data_files/management/commands/find_pending_submissions.py rename to tdrs-backend/tdpservice/data_files/tasks.py index 0eb88661a..30b69831d 100644 --- a/tdrs-backend/tdpservice/data_files/management/commands/find_pending_submissions.py +++ b/tdrs-backend/tdpservice/data_files/tasks.py @@ -1,5 +1,6 @@ -"""Discover files stuck in a 'Pending' status and notify System Administrators.""" +"""Celery shared tasks for use in scheduled jobs.""" +from celery import shared_task from datetime import datetime, timedelta from django.utils import timezone from django.core.management.base import BaseCommand @@ -34,17 +35,15 @@ def get_stuck_files(): return stuck_files -class Command(BaseCommand): +@shared_task +def notify_stuck_files(): """Find files stuck in 'Pending' and notify SysAdmins.""" + recipients = User.objects.filter( + account_approval_status=AccountApprovalStatusChoices.APPROVED, + groups=Group.objects.get(name='OFA System Admin') + ).values_list('username', flat=True).distinct() - def handle(self, *args, **options): - """Run when the management command is invoked.""" - recipients = User.objects.filter( - account_approval_status=AccountApprovalStatusChoices.APPROVED, - groups=Group.objects.get(name='OFA System Admin') - ).values_list('username', flat=True).distinct() + stuck_files = get_stuck_files() - stuck_files = get_stuck_files() - - if stuck_files.count() > 0: - send_stuck_file_email(stuck_files, recipients) + if stuck_files.count() > 0: + send_stuck_file_email(stuck_files, recipients) diff --git a/tdrs-backend/tdpservice/settings/common.py b/tdrs-backend/tdpservice/settings/common.py index 89acbe10c..dd53d0559 100644 --- a/tdrs-backend/tdpservice/settings/common.py +++ b/tdrs-backend/tdpservice/settings/common.py @@ -486,6 +486,10 @@ class Common(Configuration): 'task': 'tdpservice.email.tasks.email_admin_num_access_requests', 'schedule': crontab(minute='0', hour='1', day_of_week='*', day_of_month='*', month_of_year='*'), # Every day at 1am UTC (9pm EST) }, + 'Email Admin Number of Stuck Files' : { + 'task': 'tdpservice.data_files.tasks.notify_stuck_files', + 'schedule': crontab(minute='0', hour='1', day_of_week='*', day_of_month='*', month_of_year='*'), # Every day at 1am UTC (9pm EST) + }, 'Email Data Analyst Q1 Upcoming Submission Deadline Reminder': { 'task': 'tdpservice.email.tasks.send_data_submission_reminder', # Feb 9 at 1pm UTC (9am EST)