diff --git a/rq/decorators.py b/rq/decorators.py index b433904c..90aebf7f 100644 --- a/rq/decorators.py +++ b/rq/decorators.py @@ -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 diff --git a/tests/test_decorator.py b/tests/test_decorator.py index f00f1a30..2521e2ec 100644 --- a/tests/test_decorator.py +++ b/tests/test_decorator.py @@ -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)