Trigger cron validation

This commit is contained in:
Ilan Steemers
2020-07-01 14:18:04 +02:00
parent f48e26fbf9
commit 532199fff3
2 changed files with 13 additions and 2 deletions

View File

@@ -106,7 +106,7 @@ def schedule(func, *args, **kwargs):
raise IntegrityError("A schedule with the same name already exists.")
# create and return the schedule
return Schedule.objects.create(
s = Schedule(
name=name,
func=func,
hook=hook,
@@ -116,8 +116,12 @@ def schedule(func, *args, **kwargs):
minutes=minutes,
repeats=repeats,
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):

View File

@@ -3,6 +3,7 @@ from multiprocessing import Event, Value
import arrow
import pytest
from django.core.exceptions import ValidationError
from django.db import IntegrityError
from django.utils import timezone
@@ -100,6 +101,12 @@ def test_scheduler(broker, monkeypatch):
assert hasattr(cron_schedule, 'pk') is True
assert cron_schedule.full_clean() is None
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
for t in Schedule.TYPE:
if t[0] == Schedule.CRON: