]> git.ipfire.org Git - pbs.git/commitdiff
jobs: Compress log files
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 19 Oct 2022 13:41:47 +0000 (13:41 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 19 Oct 2022 13:41:47 +0000 (13:41 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/buildservice/jobs.py
src/buildservice/uploads.py

index 7c210830f08f2c6bc8b4d1f7fbf409f821dbce9c..c1c734155609317d3ae0dfd006bd22263ce17939 100644 (file)
@@ -2,6 +2,7 @@
 
 import asyncio
 import datetime
+import gzip
 import hashlib
 import logging
 import os
@@ -382,11 +383,12 @@ class Job(base.DataObject):
                        "jobs",
                        self.uuid[0:2],
                        self.uuid[2:4],
-                       "%s.log" % self.uuid[4:],
+                       "%s.log.gz" % self.uuid[4:],
                )
 
-               # Copy file to its destination
-               await self.backend.copy(upload.path, path)
+               # Open the destination path
+               with gzip.open(path, "wb", compresslevel=9) as f:
+                       await upload.copyinto(f)
 
                # Compute a digest for integrity
                digest = await upload.digest("blake2s")
index cc926cd4b0852dcbedc7f131eedef0ec84306b17..41c4b9dca0f6a7725ab2b39748bd9d019adb4221 100644 (file)
@@ -312,3 +312,14 @@ class Upload(base.DataObject):
 
                # Return the digest
                return h.digest()
+
+       async def copyinto(self, dst):
+               """
+                       Copies the content of this upload into the destination file descriptor.
+               """
+               return await asyncio.to_thread(self._copyinfo, dst)
+
+       def _copyinto(self, dst):
+               # Open the source file and copy it into the destination file descriptor
+               with open(self.path, "rb") as src:
+                       shutil.copyfileobj(src, dst)