]> git.ipfire.org Git - pbs.git/commitdiff
jobs: Limit the amount of concurrent log tail operations
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 24 Jan 2025 17:16:43 +0000 (17:16 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 24 Jan 2025 17:16:43 +0000 (17:16 +0000)
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 <michael.tremer@ipfire.org>
src/buildservice/jobs.py

index c343c012e82008cb7a03305ee41bf721be36ffae..38a5a16427ced2cd7601a5b3a112e42958f8f789 100644 (file)
@@ -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