From 2ead7aa8bafb49dd362213f48c3461e485d8d0a5 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Fri, 24 Jan 2025 17:16:43 +0000 Subject: [PATCH] jobs: Limit the amount of concurrent log tail operations This way we will ensure that we access one file at a time and put the others in a queue to not starve IO too hard. Signed-off-by: Michael Tremer --- src/buildservice/jobs.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/buildservice/jobs.py b/src/buildservice/jobs.py index c343c012..38a5a164 100644 --- a/src/buildservice/jobs.py +++ b/src/buildservice/jobs.py @@ -977,18 +977,21 @@ class Job(database.Base, database.BackendMixin, database.SoftDeleteMixin): # Tail Log + tail_ratelimiter = asyncio.Semaphore(1) + async def tail_log(self, limit): """ Tails the log file (i.e. returns the N last lines) """ - # Open the log file - try: - with await self.open_log() as f: - return await asyncio.to_thread(collections.deque, f, limit) + async with self.tail_ratelimiter: + # Open the log file + try: + with await self.open_log() as f: + return await asyncio.to_thread(collections.deque, f, limit) - # Return nothing if the log could not be opened - except FileNotFoundError as e: - return [] + # Return nothing if the log could not be opened + except FileNotFoundError as e: + return [] # Import the logfile -- 2.47.3