import contextlib
import datetime
import lzma
+import os
import os.path
import sqlite3
import subprocess
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
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()
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()