From 54a00fa17625e0aaea386b139dea89a5e1bf40e9 Mon Sep 17 00:00:00 2001 From: Clemens Stolle Date: Fri, 26 Apr 2024 13:13:45 +0200 Subject: [PATCH] python: wait for jobs to finalize on close --- python/bullmq/worker.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/python/bullmq/worker.py b/python/bullmq/worker.py index be988e95af..803196e5d1 100644 --- a/python/bullmq/worker.py +++ b/python/bullmq/worker.py @@ -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()