diff options
author | Helmut Grohne <helmut@subdivi.de> | 2020-10-05 21:55:42 +0200 |
---|---|---|
committer | Helmut Grohne <helmut@subdivi.de> | 2020-10-05 21:55:42 +0200 |
commit | 9bc1247357f26c02f55b2dbac0e39879bc1f194f (patch) | |
tree | f68560291381f6b86eb4e5c324c20b7fccaf1e4a | |
parent | 7b9284d2e4e5015298d67e2f22c19cf8cec1c320 (diff) | |
download | crossqa-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.
-rwxr-xr-x | build.py | 59 | ||||
-rw-r--r-- | schema.sql | 5 |
2 files changed, 43 insertions, 21 deletions
@@ -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() @@ -46,3 +46,8 @@ CREATE TABLE bugs ( title TEXT, patched BOOLEAN NOT NULL CHECK (patched in (0, 1))); CREATE INDEX bugs_affects_index ON bugs(affects); + +CREATE TABLE building ( + source TEXT NOT NULL, + architecture TEXT NOT NULL, + pid INTEGER NOT NULL); |