mirror of
https://github.com/django-q2/django-q2.git
synced 2026-10-07 19:28:11 +08:00
adds catch_up configuration option
When a cluster hasn't run for a while, the default behavior is to keep executing schedules until they are caught up with the present time. By setting `catch_up` to False, schedules will not play catch up and instead get rescheduled to the future.
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
from datetime import timedelta
|
||||
from multiprocessing import Queue, Event, Value
|
||||
|
||||
import pytest
|
||||
import arrow
|
||||
|
||||
from django.utils import timezone
|
||||
|
||||
from django_q.conf import redis_client
|
||||
from django_q.conf import redis_client, Conf
|
||||
from django_q.cluster import pusher, worker, monitor, scheduler
|
||||
from django_q.tasks import Schedule, fetch, schedule as create_schedule, queue_size
|
||||
|
||||
@@ -34,7 +36,7 @@ def test_scheduler(r):
|
||||
# push it
|
||||
pusher(task_queue, stop_event, list_key=list_key, r=r)
|
||||
assert task_queue.qsize() == 1
|
||||
assert queue_size(list_key=list_key,r=r) == 0
|
||||
assert queue_size(list_key=list_key, r=r) == 0
|
||||
task_queue.put('STOP')
|
||||
# let a worker handle them
|
||||
result_queue = Queue()
|
||||
@@ -96,7 +98,27 @@ def test_scheduler(r):
|
||||
kwargs='word="django"',
|
||||
schedule_type=Schedule.DAILY
|
||||
)
|
||||
# scheduler
|
||||
scheduler(list_key=list_key)
|
||||
# ONCE schedule should be deleted
|
||||
assert Schedule.objects.filter(pk=once_schedule.pk).exists() is False
|
||||
# Catch up On
|
||||
Conf.CATCH_UP = True
|
||||
now = timezone.now()
|
||||
schedule = create_schedule('django_q.tests.tasks.word_multiply',
|
||||
2,
|
||||
word='catch_up',
|
||||
schedule_type=Schedule.HOURLY,
|
||||
next_run=timezone.now() - timedelta(hours=12),
|
||||
repeats=-1
|
||||
)
|
||||
scheduler(list_key=list_key)
|
||||
schedule = Schedule.objects.get(pk=schedule.pk)
|
||||
assert schedule.next_run < now
|
||||
# Catch up off
|
||||
Conf.CATCH_UP = False
|
||||
scheduler(list_key=list_key)
|
||||
schedule = Schedule.objects.get(pk=schedule.pk)
|
||||
assert schedule.next_run > now
|
||||
# Done
|
||||
r.delete(list_key)
|
||||
|
||||
Reference in New Issue
Block a user