|
|
@ -70,21 +70,44 @@ class TestDecorator(RQTestCase):
|
|
|
|
result = hello.delay()
|
|
|
|
result = hello.delay()
|
|
|
|
self.assertEqual(result.ttl, 30)
|
|
|
|
self.assertEqual(result.ttl, 30)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_decorator_accepts_meta_as_argument(self):
|
|
|
|
|
|
|
|
"""Ensure that passing in meta to the decorator sets the meta on the job
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
# Ensure default
|
|
|
|
|
|
|
|
result = decorated_job.delay(1, 2)
|
|
|
|
|
|
|
|
self.assertEqual(result.meta, {})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
test_meta = {
|
|
|
|
|
|
|
|
'metaKey1': 1,
|
|
|
|
|
|
|
|
'metaKey2': 2,
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@job('default', meta=test_meta)
|
|
|
|
|
|
|
|
def hello():
|
|
|
|
|
|
|
|
return 'Hello'
|
|
|
|
|
|
|
|
result = hello.delay()
|
|
|
|
|
|
|
|
self.assertEqual(result.meta, test_meta)
|
|
|
|
|
|
|
|
|
|
|
|
def test_decorator_accepts_result_depends_on_as_argument(self):
|
|
|
|
def test_decorator_accepts_result_depends_on_as_argument(self):
|
|
|
|
"""Ensure that passing in depends_on to the decorator sets the
|
|
|
|
"""Ensure that passing in depends_on to the decorator sets the
|
|
|
|
correct dependency on the job
|
|
|
|
correct dependency on the job
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
|
|
|
|
# Ensure default
|
|
|
|
|
|
|
|
result = decorated_job.delay(1, 2)
|
|
|
|
|
|
|
|
self.assertEqual(result.dependency, None)
|
|
|
|
|
|
|
|
self.assertEqual(result._dependency_id, None)
|
|
|
|
|
|
|
|
|
|
|
|
@job(queue='queue_name')
|
|
|
|
@job(queue='queue_name')
|
|
|
|
def foo():
|
|
|
|
def foo():
|
|
|
|
return 'Firstly'
|
|
|
|
return 'Firstly'
|
|
|
|
|
|
|
|
|
|
|
|
@job(queue='queue_name')
|
|
|
|
foo_job = foo.delay()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@job(queue='queue_name', depends_on=foo_job)
|
|
|
|
def bar():
|
|
|
|
def bar():
|
|
|
|
return 'Secondly'
|
|
|
|
return 'Secondly'
|
|
|
|
|
|
|
|
|
|
|
|
foo_job = foo.delay()
|
|
|
|
bar_job = bar.delay()
|
|
|
|
bar_job = bar.delay(depends_on=foo_job)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.assertIsNone(foo_job._dependency_id)
|
|
|
|
self.assertIsNone(foo_job._dependency_id)
|
|
|
|
|
|
|
|
|
|
|
@ -92,6 +115,39 @@ class TestDecorator(RQTestCase):
|
|
|
|
|
|
|
|
|
|
|
|
self.assertEqual(bar_job._dependency_id, foo_job.id)
|
|
|
|
self.assertEqual(bar_job._dependency_id, foo_job.id)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_decorator_delay_accepts_depends_on_as_argument(self):
|
|
|
|
|
|
|
|
"""Ensure that passing in depends_on to the delay method of
|
|
|
|
|
|
|
|
a decorated function overrides the depends_on set in the
|
|
|
|
|
|
|
|
constructor.
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
# Ensure default
|
|
|
|
|
|
|
|
result = decorated_job.delay(1, 2)
|
|
|
|
|
|
|
|
self.assertEqual(result.dependency, None)
|
|
|
|
|
|
|
|
self.assertEqual(result._dependency_id, None)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@job(queue='queue_name')
|
|
|
|
|
|
|
|
def foo():
|
|
|
|
|
|
|
|
return 'Firstly'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@job(queue='queue_name')
|
|
|
|
|
|
|
|
def bar():
|
|
|
|
|
|
|
|
return 'Firstly'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
foo_job = foo.delay()
|
|
|
|
|
|
|
|
bar_job = bar.delay()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@job(queue='queue_name', depends_on=foo_job)
|
|
|
|
|
|
|
|
def baz():
|
|
|
|
|
|
|
|
return 'Secondly'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
baz_job = bar.delay(depends_on=bar_job)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.assertIsNone(foo_job._dependency_id)
|
|
|
|
|
|
|
|
self.assertIsNone(bar_job._dependency_id)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.assertEqual(baz_job.dependency, bar_job)
|
|
|
|
|
|
|
|
self.assertEqual(baz_job._dependency_id, bar_job.id)
|
|
|
|
|
|
|
|
|
|
|
|
@mock.patch('rq.queue.resolve_connection')
|
|
|
|
@mock.patch('rq.queue.resolve_connection')
|
|
|
|
def test_decorator_connection_laziness(self, resolve_connection):
|
|
|
|
def test_decorator_connection_laziness(self, resolve_connection):
|
|
|
|
"""Ensure that job decorator resolve connection in `lazy` way """
|
|
|
|
"""Ensure that job decorator resolve connection in `lazy` way """
|
|
|
|