"""
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