From: Michael Tremer Date: Thu, 17 Aug 2023 10:16:54 +0000 (+0000) Subject: jobs: Tail logs more efficiently X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=965c9d2f88a1525f8c3cc6acc07b7da8e6c56ead;p=pbs.git jobs: Tail logs more efficiently Signed-off-by: Michael Tremer --- diff --git a/src/buildservice/jobs.py b/src/buildservice/jobs.py index 87800ad9..56857634 100644 --- a/src/buildservice/jobs.py +++ b/src/buildservice/jobs.py @@ -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