aboutsummaryrefslogtreecommitdiff
path: root/guix-build-coordinator/datastore/sqlite.scm
diff options
context:
space:
mode:
authorChristopher Baines <mail@cbaines.net>2020-06-27 21:33:24 +0100
committerChristopher Baines <mail@cbaines.net>2020-07-01 17:43:38 +0100
commitb5c4e8a4528e2c819176cbe070f6fd8e3e34facd (patch)
tree9d026e882411fc79b0736cdc9c97352d64ca7ef1 /guix-build-coordinator/datastore/sqlite.scm
parentab51128ee62b22971ea8b52d550e09d1c38f8ecd (diff)
downloadbuild-coordinator-b5c4e8a4528e2c819176cbe070f6fd8e3e34facd.tar
build-coordinator-b5c4e8a4528e2c819176cbe070f6fd8e3e34facd.tar.gz
Support storing when builds start
This isn't particularly accurate, what's actually being stored is the current time when the record is inserted in to the coordinator database, but that should happen just before the agent starts the build, so hopefully that's good enough.
Diffstat (limited to 'guix-build-coordinator/datastore/sqlite.scm')
-rw-r--r--guix-build-coordinator/datastore/sqlite.scm53
1 files changed, 53 insertions, 0 deletions
diff --git a/guix-build-coordinator/datastore/sqlite.scm b/guix-build-coordinator/datastore/sqlite.scm
index 88db088..db9f807 100644
--- a/guix-build-coordinator/datastore/sqlite.scm
+++ b/guix-build-coordinator/datastore/sqlite.scm
@@ -27,6 +27,8 @@
datastore-new-agent
datastore-list-agents
datastore-find-agent
+ datastore-store-build-start
+ datastore-find-build-starts
datastore-count-setup-failures
datastore-list-setup-failures-for-build
datastore-fetch-setup-failures
@@ -592,6 +594,57 @@ VALUES "
(store-output-metadata db build-id output-metadata))))
#t)
+(define-method (datastore-store-build-start
+ (datastore <sqlite-datastore>)
+ build-id
+ agent-id)
+
+ (call-with-worker-thread
+ (slot-ref datastore 'worker-writer-thread-channel)
+ (lambda (db)
+ (sqlite-exec
+ db
+ (string-append
+ "
+INSERT INTO build_starts (
+ build_id, agent_id, start_time
+) VALUES ('"
+ build-id "', '"
+ agent-id "', "
+ "datetime('now')"
+ ")")))))
+
+(define-method (datastore-find-build-starts
+ (datastore <sqlite-datastore>)
+ build-id)
+ (call-with-worker-thread
+ (slot-ref datastore 'worker-reader-thread-channel)
+ (lambda (db)
+ (let ((statement
+ (sqlite-prepare
+ db
+ "
+SELECT start_time, agent_id
+FROM build_starts
+WHERE build_id = :build_id
+ORDER BY start_time DESC")))
+
+ (sqlite-bind-arguments
+ statement
+ #:build_id build-id)
+
+ (let ((result
+ (sqlite-map
+ (match-lambda
+ (#(start_time agent_id)
+ `((start-time . ,(match (strptime "%F %T" start_time)
+ ((parts . _) parts)))
+ (agent-id . ,agent_id))))
+ statement)))
+ (sqlite-reset statement)
+
+ result)))))
+
(define (insert-setup-failure-and-remove-allocation
db
build-id