Skip to content

Commit

Permalink
convert to celery task
Browse files Browse the repository at this point in the history
  • Loading branch information
jtimpe committed Sep 20, 2024
1 parent 0552872 commit cc32905
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 12 deletions.
Empty file.
Empty file.
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)
4 changes: 4 additions & 0 deletions tdrs-backend/tdpservice/settings/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit cc32905

Please sign in to comment.