From 4f3e91397b269b84373044f6bd0d89f651cd0bcd Mon Sep 17 00:00:00 2001 From: EdgeNeko Date: Sat, 6 Jul 2024 14:13:25 +0800 Subject: [PATCH] Wait for all the images in the queue to be indexed before server shutdown --- app/Services/upload_service.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/Services/upload_service.py b/app/Services/upload_service.py index d5f7585..51b59fb 100644 --- a/app/Services/upload_service.py +++ b/app/Services/upload_service.py @@ -100,3 +100,9 @@ async def sync_upload_image(self, img_data: ImageData, img_bytes: bytes, skip_oc def get_queue_size(self): return self._queue.qsize() + + async def on_exit(self): # pragma: no cover Hard to test in UT. + if self.get_queue_size() != 0: + logger.warning("There are still {} images in the upload queue. Waiting for upload process to be completed.", + self.get_queue_size()) + await self._queue.join()