Merge pull request #445 from conslo/patch-1

allow depends_on to be a job id or a job itself
main
Selwin Ong 10 years ago
commit 786d3c5887

5
.gitignore vendored

@ -9,4 +9,7 @@
/build
.tox
.vagrant
Vagrantfile
Vagrantfile
# PyCharm
.idea

@ -189,6 +189,8 @@ class Queue(object):
# If WatchError is raised in the process, that means something else is
# modifying the dependency. In this case we simply retry
if depends_on is not None:
if not isinstance(depends_on, self.job_class):
depends_on = Job.fetch(id=depends_on, connection=self.connection)
with self.connection.pipeline() as pipe:
while True:
try:

@ -352,6 +352,23 @@ class TestQueue(RQTestCase):
self.assertEqual(q.job_ids, [job.id])
self.assertEqual(job.timeout, Queue.DEFAULT_TIMEOUT)
def test_enqueue_job_with_dependency_by_id(self):
"""Enqueueing jobs should work as expected by id as well as job-objects."""
parent_job = Job.create(func=say_hello)
# We need to save the job for the ID to exist in redis
parent_job.save()
q = Queue()
q.enqueue_call(say_hello, depends_on=parent_job.id)
self.assertEqual(q.job_ids, [])
# Jobs dependent on finished jobs are immediately enqueued
parent_job.set_status(Status.FINISHED)
parent_job.save()
job = q.enqueue_call(say_hello, depends_on=parent_job.id)
self.assertEqual(q.job_ids, [job.id])
self.assertEqual(job.timeout, Queue.DEFAULT_TIMEOUT)
def test_enqueue_job_with_dependency_and_timeout(self):
"""Jobs still know their specified timeout after being scheduled as a dependency."""
# Job with unfinished dependency is not immediately enqueued

Loading…
Cancel
Save