aboutsummaryrefslogtreecommitdiff
path: root/guix-build-coordinator
diff options
context:
space:
mode:
authorChristopher Baines <mail@cbaines.net>2020-04-06 20:10:27 +0100
committerChristopher Baines <mail@cbaines.net>2020-04-10 20:34:47 +0100
commitc41f786193ac023582c90c20d94091a3bdb3b28b (patch)
tree3cb3c2391720541a6c5f6418bb0a00dcadf8d373 /guix-build-coordinator
parent549e3cca1ace8c5ed50b3f78ef737c5120141515 (diff)
downloadbuild-coordinator-c41f786193ac023582c90c20d94091a3bdb3b28b.tar
build-coordinator-c41f786193ac023582c90c20d94091a3bdb3b28b.tar.gz
Implement storing builds
Diffstat (limited to 'guix-build-coordinator')
-rw-r--r--guix-build-coordinator/coordinator.scm19
-rw-r--r--guix-build-coordinator/datastore.scm3
-rw-r--r--guix-build-coordinator/datastore/sqlite.scm33
3 files changed, 50 insertions, 5 deletions
diff --git a/guix-build-coordinator/coordinator.scm b/guix-build-coordinator/coordinator.scm
index 2851b2c..a7222f0 100644
--- a/guix-build-coordinator/coordinator.scm
+++ b/guix-build-coordinator/coordinator.scm
@@ -20,11 +20,24 @@
(define-module (guix-build-coordinator coordinator)
#:use-module (guix derivations)
+ #:use-module (guix-build-coordinator utils)
#:use-module (guix-build-coordinator datastore)
#:export (submit-build))
-(define (submit-build datastore derivation-file)
+(define* (submit-build datastore derivation-file
+ #:key
+ requested-uuid
+ (priority 0))
(let ((derivation
- (read-derivation-from-file derivation-file)))
+ (read-derivation-from-file derivation-file))
+ (uuid
+ (or requested-uuid (random-v4-uuid))))
- (datastore-store-derivation datastore derivation)))
+ (datastore-store-derivation datastore derivation)
+
+ (datastore-store-build datastore
+ derivation-file
+ uuid
+ priority)
+
+ uuid))
diff --git a/guix-build-coordinator/datastore.scm b/guix-build-coordinator/datastore.scm
index 968363d..4a33b60 100644
--- a/guix-build-coordinator/datastore.scm
+++ b/guix-build-coordinator/datastore.scm
@@ -4,7 +4,8 @@
#:use-module (guix-build-coordinator datastore abstract)
#:use-module (guix-build-coordinator datastore sqlite)
;; #:use-module (guix-build-coordinator datastore postgresql)
- #:re-export (datastore-store-derivation)
+ #:re-export (datastore-store-derivation
+ datastore-store-build)
#:export (database-uri->datastore))
(define (database-uri->datastore database)
diff --git a/guix-build-coordinator/datastore/sqlite.scm b/guix-build-coordinator/datastore/sqlite.scm
index d50a521..e593088 100644
--- a/guix-build-coordinator/datastore/sqlite.scm
+++ b/guix-build-coordinator/datastore/sqlite.scm
@@ -9,7 +9,8 @@
#:use-module (guix-build-coordinator config)
#:use-module (guix-build-coordinator datastore abstract)
#:export (sqlite-datastore
- datastore-store-derivation))
+ datastore-store-derivation
+ datastore-store-build))
(define-class <sqlite-datastore> (<abstract-datastore>)
worker-thread-channel)
@@ -45,6 +46,19 @@
(sqlite-exec db "COMMIT TRANSACTION;")))
#t)
+(define-method (datastore-store-build
+ (datastore <sqlite-datastore>)
+ derivation-name
+ uuid
+ priority)
+ (call-with-worker-thread
+ (slot-ref datastore 'worker-thread-channel)
+ (lambda (db)
+ (sqlite-exec db "BEGIN TRANSACTION;")
+ (insert-build db uuid derivation-name priority)
+ (sqlite-exec db "COMMIT TRANSACTION;")))
+ #t)
+
(define (db-open database)
(define flags
(list SQLITE_OPEN_READWRITE
@@ -188,3 +202,20 @@ INSERT INTO derivation_outputs (derivation_name, name, output) VALUES "
derivation-outputs)
", ")
";")))
+
+(define (insert-build db uuid derivation-name priority)
+ (let ((statement
+ (sqlite-prepare
+ db
+ "
+INSERT INTO builds (uuid, derivation_name, priority)
+VALUES (:uuid, :derivation_name, :priority)")))
+
+ (sqlite-bind-arguments
+ statement
+ #:uuid uuid
+ #:derivation_name derivation-name
+ #:priority priority)
+
+ (sqlite-step statement)
+ (sqlite-reset statement)))