mirror of
https://github.com/django-q2/django-q2.git
synced 2026-10-05 13:58:11 +08:00
Adds a check for duplicate schedule names.
This should prevent the accidental repeated creation of schedules.
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
from multiprocessing import Queue, Value
|
||||
|
||||
# django
|
||||
from django.db import IntegrityError
|
||||
from django.utils import timezone
|
||||
|
||||
# local
|
||||
@@ -75,6 +76,11 @@ def schedule(func, *args, **kwargs):
|
||||
repeats = kwargs.pop('repeats', -1)
|
||||
next_run = kwargs.pop('next_run', timezone.now())
|
||||
|
||||
# check for name duplicates instead of am unique constraint
|
||||
if name and Schedule.objects.filter(name=name).exists():
|
||||
raise IntegrityError("A schedule with the same name already exists.")
|
||||
|
||||
# create and return the schedule
|
||||
return Schedule.objects.create(name=name,
|
||||
func=func,
|
||||
hook=hook,
|
||||
|
||||
Reference in New Issue
Block a user