aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--guix-build-coordinator/datastore.scm1
-rw-r--r--guix-build-coordinator/datastore/sqlite.scm24
2 files changed, 25 insertions, 0 deletions
diff --git a/guix-build-coordinator/datastore.scm b/guix-build-coordinator/datastore.scm
index 1a890d4..06334cb 100644
--- a/guix-build-coordinator/datastore.scm
+++ b/guix-build-coordinator/datastore.scm
@@ -9,6 +9,7 @@
datastore-find-build-output))
(re-export datastore-update)
+(re-export datastore-call-with-transaction)
(re-export datastore-store-derivation)
(re-export datastore-store-build)
(re-export datastore-new-agent)
diff --git a/guix-build-coordinator/datastore/sqlite.scm b/guix-build-coordinator/datastore/sqlite.scm
index 159124c..6a49f19 100644
--- a/guix-build-coordinator/datastore/sqlite.scm
+++ b/guix-build-coordinator/datastore/sqlite.scm
@@ -11,6 +11,7 @@
#:use-module (guix-build-coordinator datastore abstract)
#:export (sqlite-datastore
datastore-update
+ datastore-call-with-transaction
datastore-store-derivation
datastore-list-related-derivations-with-no-build-for-outputs
datastore-list-failed-builds-with-blocking-count
@@ -131,6 +132,29 @@
result))
(thunk)))
+(define* (datastore-call-with-transaction datastore thunk
+ #:key readonly?)
+ (call-with-worker-thread
+ (slot-ref datastore (if readonly?
+ 'worker-reader-thread-channel
+ 'worker-writer-thread-channel))
+ (lambda (db)
+ (sqlite-exec db "BEGIN TRANSACTION;")
+ (with-exception-handler
+ (lambda (exn)
+ (simple-format (current-error-port)
+ "error: sqlite: ~A\n"
+ exn)
+ (sqlite-exec db "ROLLBACK TRANSACTION;")
+ (raise-exception exn))
+ (lambda ()
+ (call-with-values
+ thunk
+ (lambda vals
+ (sqlite-exec db "COMMIT TRANSACTION;")
+ (apply values vals))))
+ #:unwind? #t))))
+
(define-method (datastore-find-agent
(datastore <sqlite-datastore>)
uuid)