cmsmanage/cmsmanage/django_q2_helper.py
Adam Goldsmith eeb83388e1
All checks were successful
Ruff / ruff (push) Successful in 29s
Test / test (push) Successful in 3m55s
Directly use q_task_group name in django-q2 ensure_scheduled helper
2024-05-23 23:23:35 -04:00

24 lines
586 B
Python

from django_q.models import Schedule
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=func.q_task_group,
defaults={
"func": f"{func.__module__}.{func.__qualname__}",
**kwargs,
},
)
def q_task_group(task_group: str):
"""Decorator to more cleanly add `q_task_group` to a function"""
def inner(func):
func.q_task_group = task_group
return func
return inner