From 46c96f9481b98b9e77d4167feb3a8bf60fbf1142 Mon Sep 17 00:00:00 2001 From: msoedov Date: Sun, 27 Apr 2014 20:02:33 +0300 Subject: [PATCH] Added depends_on to job decorator --- rq/decorators.py | 6 +++++- tests/test_decorator.py | 22 ++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/rq/decorators.py b/rq/decorators.py index b433904..90aebf7 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 f00f1a3..2521e2e 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)