From d81f210a5f5968fc040e820946fb672deb24bd01 Mon Sep 17 00:00:00 2001 From: Clemens Stolle Date: Sun, 28 Apr 2024 18:58:35 +0200 Subject: [PATCH] fix(worker): wait for jobs to finalize on close (#2545) [python] --- 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()