diff options
author | Christopher Baines <mail@cbaines.net> | 2020-06-20 12:04:19 +0100 |
---|---|---|
committer | Christopher Baines <mail@cbaines.net> | 2020-06-20 12:04:19 +0100 |
commit | 52e6f12cee2680739954afd2e3a8c2d28d835fc6 (patch) | |
tree | 193462c32abe15bbcd6a9633a96df41c45aec184 | |
parent | fa6db19ff1b60ca3faab30e37787bbf9f486f5f0 (diff) | |
download | build-coordinator-52e6f12cee2680739954afd2e3a8c2d28d835fc6.tar build-coordinator-52e6f12cee2680739954afd2e3a8c2d28d835fc6.tar.gz |
Add datastore-call-with-transaction
-rw-r--r-- | guix-build-coordinator/datastore.scm | 1 | ||||
-rw-r--r-- | guix-build-coordinator/datastore/sqlite.scm | 24 |
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) |