Added depends_on to job decorator

main
msoedov 11 years ago
parent dbcba85815
commit 46c96f9481

@ -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

@ -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)

Loading…
Cancel
Save