diff --git a/rq/registry.py b/rq/registry.py index 65b9796..7e0fcaf 100644 --- a/rq/registry.py +++ b/rq/registry.py @@ -12,9 +12,11 @@ class BaseRegistry(object): Each job is stored as a key in the registry, scored by expiration time (unix timestamp). """ + key_template = 'rq:registry:{0}' def __init__(self, name='default', connection=None): self.name = name + self.key = self.key_template.format(name) self.connection = resolve_connection(connection) def __len__(self): @@ -66,10 +68,7 @@ class StartedJobRegistry(BaseRegistry): Jobs are added to registry right before they are executed and removed right after completion (success or failure). """ - - def __init__(self, name='default', connection=None): - super(StartedJobRegistry, self).__init__(name, connection) - self.key = 'rq:wip:{0}'.format(name) + key_template = 'rq:wip:{0}' def cleanup(self, timestamp=None): """Remove expired jobs from registry and add them to FailedQueue. @@ -105,10 +104,7 @@ class FinishedJobRegistry(BaseRegistry): Registry of jobs that have been completed. Jobs are added to this registry after they have successfully completed for monitoring purposes. """ - - def __init__(self, name='default', connection=None): - super(FinishedJobRegistry, self).__init__(name, connection) - self.key = 'rq:finished:{0}'.format(name) + key_template = 'rq:finished:{0}' def cleanup(self, timestamp=None): """Remove expired jobs from registry. @@ -125,10 +121,7 @@ class DeferredJobRegistry(BaseRegistry): """ Registry of deferred jobs (waiting for another job to finish). """ - - def __init__(self, name='default', connection=None): - super(DeferredJobRegistry, self).__init__(name, connection) - self.key = 'rq:deferred:{0}'.format(name) + key_template = 'rq:deferred:{0}' def cleanup(self): """This method is only here to prevent errors because this method is diff --git a/tests/test_registry.py b/tests/test_registry.py index 95bb4ae..c3bbb7c 100644 --- a/tests/test_registry.py +++ b/tests/test_registry.py @@ -19,6 +19,9 @@ class TestRegistry(RQTestCase): super(TestRegistry, self).setUp() self.registry = StartedJobRegistry(connection=self.testconn) + def test_key(self): + self.assertEqual(self.registry.key, 'rq:wip:default') + def test_add_and_remove(self): """Adding and removing job to StartedJobRegistry.""" timestamp = current_timestamp() @@ -129,6 +132,9 @@ class TestFinishedJobRegistry(RQTestCase): super(TestFinishedJobRegistry, self).setUp() self.registry = FinishedJobRegistry(connection=self.testconn) + def test_key(self): + self.assertEqual(self.registry.key, 'rq:finished:default') + def test_cleanup(self): """Finished job registry removes expired jobs.""" timestamp = current_timestamp() @@ -165,6 +171,9 @@ class TestDeferredRegistry(RQTestCase): super(TestDeferredRegistry, self).setUp() self.registry = DeferredJobRegistry(connection=self.testconn) + def test_key(self): + self.assertEqual(self.registry.key, 'rq:deferred:default') + def test_add(self): """Adding a job to DeferredJobsRegistry.""" job = Job()