summaryrefslogtreecommitdiff
path: root/build.py
diff options
context:
space:
mode:
authorHelmut Grohne <helmut@subdivi.de>2020-10-05 21:55:42 +0200
committerHelmut Grohne <helmut@subdivi.de>2020-10-05 21:55:42 +0200
commit9bc1247357f26c02f55b2dbac0e39879bc1f194f (patch)
treef68560291381f6b86eb4e5c324c20b7fccaf1e4a /build.py
parent7b9284d2e4e5015298d67e2f22c19cf8cec1c320 (diff)
downloadcrossqa-9bc1247357f26c02f55b2dbac0e39879bc1f194f.tar.gz
support concurrent builds
Add new table "building" for recording builds in progress. When a concurrent build is issued, it will avoid building a source package that is presently built. It will also avoid building for an architecture that is presently built for. The latter condition helps reduce the number of satisfiability issues.
Diffstat (limited to 'build.py')
-rwxr-xr-xbuild.py59
1 files changed, 38 insertions, 21 deletions
diff --git a/build.py b/build.py
index 3312bd0..340802b 100755
--- a/build.py
+++ b/build.py
@@ -6,6 +6,7 @@ import collections
import contextlib
import datetime
import lzma
+import os
import os.path
import sqlite3
import subprocess
@@ -50,6 +51,7 @@ def main():
args = argp.parse_args()
db = sqlite3.connect("db", detect_types=sqlite3.PARSE_DECLTYPES)
with contextlib.closing(db.cursor()) as cur:
+ cur.execute("BEGIN IMMEDIATE;")
cur.execute("""
SELECT d.source, d.version, d.architecture, r.id
FROM depstate AS d
@@ -59,6 +61,9 @@ def main():
JOIN depcheck
ON d.architecture = depcheck.architecture
WHERE d.satisfiable = 1 AND depcheck.giveback = 0
+ AND NOT EXISTS (SELECT 1 FROM building
+ WHERE d.source = building.source
+ OR d.architecture = building.architecture)
ORDER BY r.priority DESC, r.requesttime ASC, random()
LIMIT 1;""")
row = cur.fetchone()
@@ -70,27 +75,39 @@ def main():
WHERE satisfiable = 1 AND giveback = 0
ORDER BY random() LIMIT 1;""")
row = cur.fetchone()
- if not row:
- print("no package satisfiable")
- time.sleep(60)
- return
- source, version, architecture, requestid = row
- print("building %s_%s for %s%s" %
- (source, version, architecture,
- "" if requestid is None else " (request %d)" % requestid))
- timestamp, success, filename, giveback = \
- do_build(source, version, architecture, args.server)
- with contextlib.closing(db.cursor()) as cur:
- cur.execute("INSERT INTO builds (source, version, architecture, success, starttime, filename) VALUES (?, ?, ?, ?, ?, ?);",
- (source, version, architecture, success, timestamp,
- filename))
- if requestid is not None:
- cur.execute("DELETE FROM buildrequests WHERE id = ?;",
- (requestid,))
- if giveback:
- cur.execute("UPDATE depcheck SET giveback = 1 WHERE architecture = ?;",
- (architecture,))
- db.commit()
+ if not row:
+ cur.execute("ROLLBACK;")
+ print("no package satisfiable")
+ time.sleep(60)
+ return
+ source, version, architecture, requestid = row
+ cur.execute("""INSERT INTO building (source, architecture, pid)
+ VALUES (?, ?, ?);""",
+ (source, architecture, os.getpid()))
+ cur.execute("COMMIT;")
+ try:
+ print("building %s_%s for %s%s" %
+ (source, version, architecture,
+ "" if requestid is None else " (request %d)" % requestid))
+ timestamp, success, filename, giveback = \
+ do_build(source, version, architecture, args.server)
+ with contextlib.closing(db.cursor()) as cur:
+ cur.execute("""INSERT INTO builds
+ (source, version, architecture, success, starttime,
+ filename) VALUES (?, ?, ?, ?, ?, ?);""",
+ (source, version, architecture, success, timestamp,
+ filename))
+ if requestid is not None:
+ cur.execute("DELETE FROM buildrequests WHERE id = ?;",
+ (requestid,))
+ if giveback:
+ cur.execute("""UPDATE depcheck SET giveback = 1
+ WHERE architecture = ?;""",
+ (architecture,))
+ finally:
+ with contextlib.closing(db.cursor()) as cur:
+ cur.execute("DELETE FROM building WHERE pid = ?;", (os.getpid(),))
+ db.commit()
if __name__ == "__main__":
main()