Merge pull request #341 from SanyerMyasoedov/master

Added depends_on to job decorator
This commit is contained in:
Vincent Driessen 2014-04-27 22:50:54 +02:00
commit 5fe82bd543
2 changed files with 27 additions and 1 deletions

View File

@ -31,7 +31,11 @@ class job(object):
queue = Queue(name=self.queue, connection=self.connection)
else:
queue = self.queue
if 'depends_on' in kwargs:
depends_on = kwargs.pop('depends_on')
else:
depends_on = None
return queue.enqueue_call(f, args=args, kwargs=kwargs,
timeout=self.timeout, result_ttl=self.result_ttl)
timeout=self.timeout, result_ttl=self.result_ttl, depends_on=depends_on)
f.delay = delay
return f

View File

@ -48,3 +48,25 @@ class TestDecorator(RQTestCase):
return 'Why hello'
result = hello.delay()
self.assertEqual(result.result_ttl, 10)
def test_decorator_accepts_result_depends_on_as_argument(self):
"""Ensure that passing in depends_on to the decorator sets the
correct dependency on the job
"""
@job(queue='queue_name')
def foo():
return 'Firstly'
@job(queue='queue_name')
def bar():
return 'Secondly'
foo_job = foo.delay()
bar_job = bar.delay(depends_on=foo_job)
self.assertIsNone(foo_job._dependency_id)
self.assertEqual(bar_job.dependency, foo_job)
self.assertEqual(bar_job._dependency_id, foo_job.id)