mirror of
https://github.com/django-q2/django-q2.git
synced 2026-10-05 04:28:12 +08:00
Trigger cron validation
This commit is contained in:
+6
-2
@@ -106,7 +106,7 @@ def schedule(func, *args, **kwargs):
|
|||||||
raise IntegrityError("A schedule with the same name already exists.")
|
raise IntegrityError("A schedule with the same name already exists.")
|
||||||
|
|
||||||
# create and return the schedule
|
# create and return the schedule
|
||||||
return Schedule.objects.create(
|
s = Schedule(
|
||||||
name=name,
|
name=name,
|
||||||
func=func,
|
func=func,
|
||||||
hook=hook,
|
hook=hook,
|
||||||
@@ -116,8 +116,12 @@ def schedule(func, *args, **kwargs):
|
|||||||
minutes=minutes,
|
minutes=minutes,
|
||||||
repeats=repeats,
|
repeats=repeats,
|
||||||
next_run=next_run,
|
next_run=next_run,
|
||||||
cron=cron
|
cron=cron,
|
||||||
)
|
)
|
||||||
|
# make sure we trigger validation
|
||||||
|
s.full_clean()
|
||||||
|
s.save()
|
||||||
|
return s
|
||||||
|
|
||||||
|
|
||||||
def result(task_id, wait=0, cached=Conf.CACHED):
|
def result(task_id, wait=0, cached=Conf.CACHED):
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ from multiprocessing import Event, Value
|
|||||||
|
|
||||||
import arrow
|
import arrow
|
||||||
import pytest
|
import pytest
|
||||||
|
from django.core.exceptions import ValidationError
|
||||||
from django.db import IntegrityError
|
from django.db import IntegrityError
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
|
|
||||||
@@ -100,6 +101,12 @@ def test_scheduler(broker, monkeypatch):
|
|||||||
assert hasattr(cron_schedule, 'pk') is True
|
assert hasattr(cron_schedule, 'pk') is True
|
||||||
assert cron_schedule.full_clean() is None
|
assert cron_schedule.full_clean() is None
|
||||||
assert cron_schedule.__unicode__() == 'django_q.tests.tasks.word_multiply'
|
assert cron_schedule.__unicode__() == 'django_q.tests.tasks.word_multiply'
|
||||||
|
with pytest.raises(ValidationError):
|
||||||
|
cron_schedule = create_schedule('django_q.tests.tasks.word_multiply',
|
||||||
|
2,
|
||||||
|
word='django',
|
||||||
|
schedule_type=Schedule.CRON,
|
||||||
|
cron="0 22 * * 1-12")
|
||||||
# All other types
|
# All other types
|
||||||
for t in Schedule.TYPE:
|
for t in Schedule.TYPE:
|
||||||
if t[0] == Schedule.CRON:
|
if t[0] == Schedule.CRON:
|
||||||
|
|||||||
Reference in New Issue
Block a user