Skip to content

Commit

Permalink
fix(worker): wait for jobs to finalize on close (#2545) [python]
Browse files Browse the repository at this point in the history
  • Loading branch information
klaemo authored Apr 28, 2024
1 parent a8c5831 commit d81f210
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion python/bullmq/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,13 +243,18 @@ async def runStalledJobsCheck(self):

async def close(self, force: bool = False):
"""
Close the worker
Closes the worker and related redis connections.
This method waits for current jobs to finalize before returning.
"""
self.closing = True
if force:
self.forceClosing = True
self.cancelProcessing()

if not force and len(self.processing) > 0:
await asyncio.wait(self.processing, return_when=asyncio.ALL_COMPLETED)

await self.blockingRedisConnection.close()
await self.redisConnection.close()

Expand Down

0 comments on commit d81f210

Please sign in to comment.