Directly use q_task_group name in django-q2 ensure_scheduled helper
All checks were successful
Ruff / ruff (push) Successful in 29s
Test / test (push) Successful in 3m55s

This commit is contained in:
Adam Goldsmith 2024-05-23 23:23:35 -04:00
parent bd1e009cc2
commit eeb83388e1
5 changed files with 8 additions and 8 deletions

View File

@ -1,9 +1,11 @@
from django_q.models import Schedule
def ensure_scheduled(name: str, func, **kwargs):
def ensure_scheduled(func, **kwargs):
if not hasattr(func, "q_task_group"):
raise ValueError("task func not decorated with @q_task_group")
Schedule.objects.update_or_create(
name=name,
name=func.q_task_group,
defaults={
"func": f"{func.__module__}.{func.__qualname__}",
**kwargs,

View File

@ -11,14 +11,12 @@ def post_migrate_callback(sender, **kwargs):
from .tasks.update_doors import q_update_all_doors
ensure_scheduled(
q_getMessagesAllDoors.q_task_group,
q_getMessagesAllDoors,
schedule_type=Schedule.MINUTES,
minutes=15,
)
ensure_scheduled(
"Update Door Controller Members and Cards",
q_update_all_doors,
schedule_type=Schedule.MINUTES,
minutes=15,

View File

@ -4,6 +4,7 @@ from typing import TypedDict
from django_q.tasks import async_task
from cmsmanage.django_q2_helper import q_task_group
from doorcontrol.hid.Credential import Credential
from doorcontrol.hid.DoorController import ROOT, E
from doorcontrol.models import AttributeScheduleRule, Door, FlagScheduleRule
@ -266,6 +267,7 @@ def update_door(door: Door, dry_run: bool = False):
# TODO: delete cardholders that are no longer members?
@q_task_group("Update Door Controller Members and Cards")
def q_update_all_doors():
for door in Door.objects.all():
async_task(

View File

@ -12,26 +12,22 @@ def post_migrate_callback(sender, **kwargs):
from .tasks.ucsAccounts import sync_accounts
ensure_scheduled(
scrape_membershipworks.q_task_group,
scrape_membershipworks,
schedule_type=Schedule.HOURLY,
)
ensure_scheduled(
scrape_events.q_task_group,
scrape_events,
schedule_type=Schedule.HOURLY,
)
ensure_scheduled(
sync_accounts.q_task_group,
sync_accounts,
schedule_type=Schedule.MINUTES,
minutes=15,
)
ensure_scheduled(
sync_accounts.q_task_group,
send_survey_emails,
schedule_type=Schedule.HOURLY,
)

View File

@ -6,6 +6,7 @@ from django.conf import settings
from django.core import mail
from django.db.models.functions import Now
from cmsmanage.django_q2_helper import q_task_group
from cmsmanage.email import TemplatedMultipartEmail
from membershipworks.models import EventExt
@ -58,6 +59,7 @@ class EventSurveyEmail(TemplatedMultipartEmail):
)
@q_task_group("Send Event Survey Emails")
def send_survey_emails():
with mail.get_connection() as conn:
for event in EventExt.objects.filter(