]> git.ipfire.org Git - pbs.git/commitdiff
jobs: Associate imported packages with the job
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 6 Feb 2025 17:52:58 +0000 (17:52 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 6 Feb 2025 17:52:58 +0000 (17:52 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/buildservice/jobs.py

index a34d0799d382c6d02be901df09a3db7f37ce0d2c..57e757ef5b314a72d787bc9630fc18cf1747de97 100644 (file)
@@ -486,29 +486,27 @@ class Job(database.Base, database.BackendMixin, database.SoftDeleteMixin):
                """
                        Will take a list of uploads and import them as packages
                """
+               packages = []
+
                # Do not allow importing any packages for test builds
                if self.is_test():
                        raise RuntimeError("Cannot import packages for test builds")
 
-               packages = []
-
                # Import all packages
                for upload in uploads:
-                       package = await self.backend.packages.create(upload)
-                       packages.append(package)
-
-               # Add them to the database
-               self.db.executemany("""
-                       INSERT INTO
-                               job_packages(
-                                       job_id,
-                                       pkg_id
-                               )
-                       VALUES(
-                               %s, %s
-                       )""", (
-                               (self.id, package.id) for package in packages
+                       packages.append(
+                               await self.backend.packages.create(upload),
                        )
+
+               # Flush the packages to the database
+               await self.db.flush()
+
+               # Associate the packages with this job
+               await self.db.insert_many(
+                       JobPackage, ({
+                               "job_id" : self.id,
+                               "pkg_id" : pkg.id,
+                       } for pkg in packages),
                )
 
                # Consume all packages