]> git.ipfire.org Git - pbs.git/commitdiff
jobs: Tail logs more efficiently
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 17 Aug 2023 10:16:54 +0000 (10:16 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 17 Aug 2023 10:16:54 +0000 (10:16 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/buildservice/jobs.py

index 87800ad953ce7e46991a802ae82db9b3459a06b9..568576343b49aabc2fc6eec5b4cb9dd0dec64d46 100644 (file)
@@ -1,6 +1,7 @@
 #!/usr/bin/python
 
 import asyncio
+import collections
 import datetime
 import gzip
 import hashlib
@@ -814,26 +815,12 @@ class Job(base.DataObject):
                # Open the log file
                try:
                        with await self.open_log() as f:
-                               return await asyncio.to_thread(self._tail_log, f, limit)
+                               return await asyncio.to_thread(collections.deque, f, limit)
 
                # Return nothing if the log could not be opened
                except FileNotFoundError as e:
                        return []
 
-       def _tail_log(self, f, limit):
-               # Create a new queue
-               q = []
-
-               # Walk through each line of the log file
-               for line in f:
-                       q.append(line)
-
-                       # Truncate the queue to limit to always have up to the last "limit" lines
-                       del q[:-limit]
-
-               # Return all lines
-               return q
-
        async def _import_logfile(self, upload):
                uuid = "%s" % self.uuid