From: Michael Tremer Date: Fri, 24 Jan 2025 17:16:43 +0000 (+0000) Subject: jobs: Limit the amount of concurrent log tail operations X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2ead7aa8bafb49dd362213f48c3461e485d8d0a5;p=pbs.git 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 --- 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