|
|
@ -7,7 +7,7 @@ from tests.fixtures import (div_by_zero, echo, Number, say_hello,
|
|
|
|
some_calculation)
|
|
|
|
some_calculation)
|
|
|
|
|
|
|
|
|
|
|
|
from rq import get_failed_queue, Queue
|
|
|
|
from rq import get_failed_queue, Queue
|
|
|
|
from rq.exceptions import InvalidJobOperationError
|
|
|
|
from rq.exceptions import InvalidJobDependency, InvalidJobOperationError
|
|
|
|
from rq.job import Job, JobStatus
|
|
|
|
from rq.job import Job, JobStatus
|
|
|
|
from rq.registry import DeferredJobRegistry
|
|
|
|
from rq.registry import DeferredJobRegistry
|
|
|
|
from rq.worker import Worker
|
|
|
|
from rq.worker import Worker
|
|
|
@ -401,6 +401,7 @@ class TestQueue(RQTestCase):
|
|
|
|
"""Jobs are enqueued only when their dependencies are finished."""
|
|
|
|
"""Jobs are enqueued only when their dependencies are finished."""
|
|
|
|
# Job with unfinished dependency is not immediately enqueued
|
|
|
|
# Job with unfinished dependency is not immediately enqueued
|
|
|
|
parent_job = Job.create(func=say_hello)
|
|
|
|
parent_job = Job.create(func=say_hello)
|
|
|
|
|
|
|
|
parent_job.save()
|
|
|
|
q = Queue()
|
|
|
|
q = Queue()
|
|
|
|
job = q.enqueue_call(say_hello, depends_on=parent_job)
|
|
|
|
job = q.enqueue_call(say_hello, depends_on=parent_job)
|
|
|
|
self.assertEqual(q.job_ids, [])
|
|
|
|
self.assertEqual(q.job_ids, [])
|
|
|
@ -417,6 +418,7 @@ class TestQueue(RQTestCase):
|
|
|
|
def test_enqueue_job_with_dependency_by_id(self):
|
|
|
|
def test_enqueue_job_with_dependency_by_id(self):
|
|
|
|
"""Can specify job dependency with job object or job id."""
|
|
|
|
"""Can specify job dependency with job object or job id."""
|
|
|
|
parent_job = Job.create(func=say_hello)
|
|
|
|
parent_job = Job.create(func=say_hello)
|
|
|
|
|
|
|
|
parent_job.save()
|
|
|
|
|
|
|
|
|
|
|
|
q = Queue()
|
|
|
|
q = Queue()
|
|
|
|
q.enqueue_call(say_hello, depends_on=parent_job.id)
|
|
|
|
q.enqueue_call(say_hello, depends_on=parent_job.id)
|
|
|
@ -433,6 +435,7 @@ class TestQueue(RQTestCase):
|
|
|
|
"""Jobs remember their timeout when enqueued as a dependency."""
|
|
|
|
"""Jobs remember their timeout when enqueued as a dependency."""
|
|
|
|
# Job with unfinished dependency is not immediately enqueued
|
|
|
|
# Job with unfinished dependency is not immediately enqueued
|
|
|
|
parent_job = Job.create(func=say_hello)
|
|
|
|
parent_job = Job.create(func=say_hello)
|
|
|
|
|
|
|
|
parent_job.save()
|
|
|
|
q = Queue()
|
|
|
|
q = Queue()
|
|
|
|
job = q.enqueue_call(say_hello, depends_on=parent_job, timeout=123)
|
|
|
|
job = q.enqueue_call(say_hello, depends_on=parent_job, timeout=123)
|
|
|
|
self.assertEqual(q.job_ids, [])
|
|
|
|
self.assertEqual(q.job_ids, [])
|
|
|
@ -445,6 +448,20 @@ class TestQueue(RQTestCase):
|
|
|
|
self.assertEqual(q.job_ids, [job.id])
|
|
|
|
self.assertEqual(q.job_ids, [job.id])
|
|
|
|
self.assertEqual(job.timeout, 123)
|
|
|
|
self.assertEqual(job.timeout, 123)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_enqueue_job_with_invalid_dependency(self):
|
|
|
|
|
|
|
|
"""Enqueuing a job fails, if the dependency does not exist at all."""
|
|
|
|
|
|
|
|
parent_job = Job.create(func=say_hello)
|
|
|
|
|
|
|
|
# without save() the job is not visible to others
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
q = Queue()
|
|
|
|
|
|
|
|
with self.assertRaises(InvalidJobDependency):
|
|
|
|
|
|
|
|
q.enqueue_call(say_hello, depends_on=parent_job)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
with self.assertRaises(InvalidJobDependency):
|
|
|
|
|
|
|
|
q.enqueue_call(say_hello, depends_on=parent_job.id)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.assertEqual(q.job_ids, [])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TestFailedQueue(RQTestCase):
|
|
|
|
class TestFailedQueue(RQTestCase):
|
|
|
|
def test_requeue_job(self):
|
|
|
|
def test_requeue_job(self):
|
|
|
|