cmsmanage/cmsmanage/django_q2_helper.py

22 lines
471 B
Python

from django_q.models import Schedule
def ensure_scheduled(name: str, func, **kwargs):
Schedule.objects.update_or_create(
name=name,
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