diff options
Diffstat (limited to 'build.py')
-rwxr-xr-x | build.py | 59 |
1 files changed, 38 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() |