24 lines
586 B
Python
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
|