mirror of
https://github.com/django-q2/django-q2.git
synced 2026-09-15 13:37:56 +08:00
Trigger cron validation
This commit is contained in:
@@ -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):
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user