Added a registry.get_job_count().

main
Selwin Ong 11 years ago
parent 783b6f9ec7
commit 41ae1ce8a7

@ -21,6 +21,15 @@ class StartedJobRegistry:
self.key = 'rq:wip:%s' % name
self.connection = resolve_connection(connection)
def __len__(self):
"""Returns the number of jobs in this registry"""
return self.get_job_count()
def get_job_count(self):
"""Returns the number of jobs in this registry"""
self.move_expired_jobs_to_failed_queue()
return self.connection.zcard(self.key)
def add(self, job, timeout, pipeline=None):
"""Adds a job to StartedJobRegistry with expiry time of now + timeout."""
score = current_timestamp() + timeout

@ -76,3 +76,10 @@ class TestQueue(RQTestCase):
worker.perform_job(job)
self.assertNotIn(job.id, registry.get_job_ids())
def test_get_job_count(self):
"""StartedJobRegistry returns the right number of job count."""
self.testconn.zadd(self.registry.key, 1, 'foo')
self.testconn.zadd(self.registry.key, 10, 'bar')
self.assertEqual(self.registry.get_job_count(), 2)
self.assertEqual(len(self.registry), 2)

Loading…
Cancel
Save