Registry objects can be instantiated by passing a queue object.

main
Selwin Ong 7 years ago
parent 0ec8030d28
commit c639018fb9

@ -15,12 +15,19 @@ class BaseRegistry(object):
job_class = Job
key_template = 'rq:registry:{0}'
def __init__(self, name='default', connection=None, job_class=None):
def __init__(self, name='default', connection=None, job_class=None,
queue=None):
if queue:
self.name = queue.name
self.connection = resolve_connection(queue.connection)
else:
self.name = name
self.key = self.key_template.format(name)
self.connection = resolve_connection(connection)
self.key = self.key_template.format(self.name)
self.job_class = backend_class(self, 'job_class', override=job_class)
def __len__(self):
"""Returns the number of jobs in this registry"""
return self.count

@ -23,6 +23,17 @@ class TestRegistry(RQTestCase):
super(TestRegistry, self).setUp()
self.registry = StartedJobRegistry(connection=self.testconn)
def test_init(self):
"""Registry can be instantiated with queue or name/Redis connection"""
queue = Queue('foo', connection=self.testconn)
registry = StartedJobRegistry(queue=queue)
self.assertEqual(registry.name, queue.name)
self.assertEqual(registry.connection, queue.connection)
registry = StartedJobRegistry('bar', self.testconn)
self.assertEqual(registry.name, 'bar')
self.assertEqual(registry.connection, self.testconn)
def test_key(self):
self.assertEqual(self.registry.key, 'rq:wip:default')

Loading…
Cancel
Save