From 1d698e7a68c31ed51619da16f9f54f14765e5105 Mon Sep 17 00:00:00 2001 From: roggervalf Date: Thu, 29 Jun 2023 10:05:13 -0500 Subject: [PATCH] feat(python): add getCompleted queue method --- python/bullmq/queue.py | 10 ++++++++++ python/tests/queue_tests.py | 4 ++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/python/bullmq/queue.py b/python/bullmq/queue.py index c72ff6c31a..99ce5d3124 100644 --- a/python/bullmq/queue.py +++ b/python/bullmq/queue.py @@ -111,6 +111,13 @@ def removeDeprecatedPriorityKey(self): """ return self.client.delete(f"{self.prefix}:{self.name}:priority") + async def getJobCountByTypes(self, *types): + result = await self.getJobCounts(*types) + sum = 0 + for attribute in result: + sum += result[attribute] + return sum + async def getJobCounts(self, *types): """ Returns the job counts for each type specified or every list/set in the queue by default. @@ -126,6 +133,9 @@ async def getJobCounts(self, *types): counts[current_types[index]] = val or 0 return counts + def getCompletedCount(self): + return self.getJobCountByTypes('completed') + def getActive(self, start = 0, end=-1): return self.getJobs(['active'], start, end, True) diff --git a/python/tests/queue_tests.py b/python/tests/queue_tests.py index 93909d89df..bba2f78492 100644 --- a/python/tests/queue_tests.py +++ b/python/tests/queue_tests.py @@ -272,8 +272,8 @@ def completing(job: Job, result): worker.off('completed', completing) - completed_count = await queue.getJobCounts('completed') - self.assertEqual(completed_count['completed'], 4) + completed_count = await queue.getCompletedCount() + self.assertEqual(completed_count, 4) await queue.close() await worker.close()