Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(python): add getCompleted queue method #2033

Merged
merged 1 commit into from
Jun 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions python/bullmq/queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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)

Expand Down
4 changes: 2 additions & 2 deletions python/tests/queue_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down