aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--guix-build-coordinator/datastore.scm2
-rw-r--r--guix-build-coordinator/datastore/sqlite.scm89
-rw-r--r--sqitch/pg/deploy/unprocessed_hook_events.sql7
-rw-r--r--sqitch/pg/revert/unprocessed_hook_events.sql7
-rw-r--r--sqitch/pg/verify/unprocessed_hook_events.sql7
-rw-r--r--sqitch/sqitch.plan1
-rw-r--r--sqitch/sqlite/deploy/unprocessed_hook_events.sql11
-rw-r--r--sqitch/sqlite/revert/unprocessed_hook_events.sql7
-rw-r--r--sqitch/sqlite/verify/unprocessed_hook_events.sql7
9 files changed, 138 insertions, 0 deletions
diff --git a/guix-build-coordinator/datastore.scm b/guix-build-coordinator/datastore.scm
index e270640..9f09bce 100644
--- a/guix-build-coordinator/datastore.scm
+++ b/guix-build-coordinator/datastore.scm
@@ -32,6 +32,8 @@
(re-export datastore-list-builds-for-derivation)
(re-export datastore-list-processed-builds)
(re-export datastore-list-unprocessed-builds)
+(re-export datastore-list-unprocessed-hook-events)
+(re-export datastore-delete-unprocessed-hook-event)
(re-export datastore-list-agent-builds)
(re-export datastore-find-derivation-outputs)
(re-export datastore-find-derivation-system)
diff --git a/guix-build-coordinator/datastore/sqlite.scm b/guix-build-coordinator/datastore/sqlite.scm
index 9ca878b..ce16c25 100644
--- a/guix-build-coordinator/datastore/sqlite.scm
+++ b/guix-build-coordinator/datastore/sqlite.scm
@@ -38,6 +38,8 @@
datastore-agent-password-exists?
datastore-list-processed-builds
datastore-list-unprocessed-builds
+ datastore-list-unprocessed-hook-events
+ datastore-delete-unprocessed-hook-event
datastore-list-agent-builds
datastore-agent-for-build
datastore-count-build-allocation-plan-entries
@@ -403,6 +405,14 @@ VALUES "
", ")))
#t)
+ (define (handle-inserting-unprocessed-hook-event db build-id result)
+ (insert-unprocessed-hook-event
+ db
+ (if (string=? result "success")
+ "build-success"
+ "build-failure")
+ (list build-id)))
+
(call-with-worker-thread
(slot-ref datastore 'worker-writer-thread-channel)
(lambda (db)
@@ -418,6 +428,9 @@ VALUES "
(insert-build-result db build-id agent-id result failure-reason)
(remove-build-allocation db build-id agent-id)
(mark-build-as-processed db build-id)
+ ;; This logic should be part of the coordinator, but it's here to be
+ ;; inside the transaction
+ (handle-inserting-unprocessed-hook-event db build-id result)
(when output-metadata
(store-output-metadata db build-id output-metadata))
(sqlite-exec db "COMMIT TRANSACTION;"))
@@ -473,6 +486,13 @@ INSERT INTO setup_failure_missing_inputs (
missing-inputs)
", "))))
+ (define (handle-inserting-unprocessed-hook-event db build-id missing-inputs)
+ (insert-unprocessed-hook-event
+ db
+ "build-missing-inputs"
+ (list build-id
+ missing-inputs)))
+
(call-with-worker-thread
(slot-ref datastore 'worker-writer-thread-channel)
(lambda (db)
@@ -491,6 +511,9 @@ INSERT INTO setup_failure_missing_inputs (
agent-id
"missing_inputs")))
(insert-missing-inputs db setup-failure-id missing-inputs))
+ ;; This logic should be part of the coordinator, but it's here to be
+ ;; inside the transaction
+ (handle-inserting-unprocessed-hook-event db build-id missing-inputs)
(sqlite-exec db "COMMIT TRANSACTION;"))
#:unwind? #t)))
#t)
@@ -821,6 +844,72 @@ ORDER BY priority DESC")))
builds)))))
+(define (insert-unprocessed-hook-event
+ db
+ event
+ arguments)
+ (let ((statement
+ (sqlite-prepare
+ db
+ "
+INSERT INTO unprocessed_hook_events (event, arguments)
+VALUES (:event, :arguments)")))
+
+ (sqlite-bind-arguments statement
+ #:event event
+ #:arguments
+ (call-with-output-string
+ (lambda (port)
+ (write arguments port))))
+
+ (sqlite-step statement)
+ (sqlite-reset statement))
+ #t)
+
+(define-method (datastore-list-unprocessed-hook-events
+ (datastore <sqlite-datastore>)
+ limit)
+ (call-with-worker-thread
+ (slot-ref datastore 'worker-reader-thread-channel)
+ (lambda (db)
+ (let ((statement
+ (sqlite-prepare
+ db
+ "
+SELECT id, event, arguments
+FROM unprocessed_hook_events
+LIMIT :limit")))
+
+ (sqlite-bind-arguments
+ statement
+ #:limit limit)
+
+ (let ((events (sqlite-map
+ (match-lambda
+ (#(id event arguments)
+ (list id
+ (string->symbol event)
+ (call-with-input-string arguments
+ (lambda (port)
+ (read port))))))
+ statement)))
+ (sqlite-reset statement)
+
+ events)))))
+
+(define-method (datastore-delete-unprocessed-hook-event
+ (datastore <sqlite-datastore>)
+ id)
+ (call-with-worker-thread
+ (slot-ref datastore 'worker-writer-thread-channel)
+ (lambda (db)
+ (sqlite-exec
+ db
+ (string-append
+ "
+DELETE FROM unprocessed_hook_events WHERE id = "
+ (number->string id))))))
+
(define-method (datastore-count-build-allocation-plan-entries
(datastore <sqlite-datastore>))
(call-with-worker-thread
diff --git a/sqitch/pg/deploy/unprocessed_hook_events.sql b/sqitch/pg/deploy/unprocessed_hook_events.sql
new file mode 100644
index 0000000..8961683
--- /dev/null
+++ b/sqitch/pg/deploy/unprocessed_hook_events.sql
@@ -0,0 +1,7 @@
+-- Deploy guix-build-coordinator:unprocessed_hook_events to pg
+
+BEGIN;
+
+-- XXX Add DDLs here.
+
+COMMIT;
diff --git a/sqitch/pg/revert/unprocessed_hook_events.sql b/sqitch/pg/revert/unprocessed_hook_events.sql
new file mode 100644
index 0000000..863cf81
--- /dev/null
+++ b/sqitch/pg/revert/unprocessed_hook_events.sql
@@ -0,0 +1,7 @@
+-- Revert guix-build-coordinator:unprocessed_hook_events from pg
+
+BEGIN;
+
+-- XXX Add DDLs here.
+
+COMMIT;
diff --git a/sqitch/pg/verify/unprocessed_hook_events.sql b/sqitch/pg/verify/unprocessed_hook_events.sql
new file mode 100644
index 0000000..5b65407
--- /dev/null
+++ b/sqitch/pg/verify/unprocessed_hook_events.sql
@@ -0,0 +1,7 @@
+-- Verify guix-build-coordinator:unprocessed_hook_events on pg
+
+BEGIN;
+
+-- XXX Add verifications here.
+
+ROLLBACK;
diff --git a/sqitch/sqitch.plan b/sqitch/sqitch.plan
index 565d142..a062e08 100644
--- a/sqitch/sqitch.plan
+++ b/sqitch/sqitch.plan
@@ -11,3 +11,4 @@ setup_failures 2020-04-13T13:05:29Z Christopher Baines <mail@cbaines.net> # Crea
output_metadata 2020-04-23T14:26:15Z Christopher Baines <mail@cbaines.net> # Create table for storing output metadata
derivation_outputs_output_index 2020-04-28T17:49:19Z Christopher Baines <mail@cbaines.net> # Add an index on derivation_outputs.output
allocator_related_indexes 2020-04-29T16:59:14Z Christopher Baines <mail@cbaines.net> # Add a few indexes that should speed up build allocation
+unprocessed_hook_events 2020-05-08T12:55:28Z Christopher Baines <mail@cbaines.net> # Add a new table unprocessed_hook_events
diff --git a/sqitch/sqlite/deploy/unprocessed_hook_events.sql b/sqitch/sqlite/deploy/unprocessed_hook_events.sql
new file mode 100644
index 0000000..33fa86b
--- /dev/null
+++ b/sqitch/sqlite/deploy/unprocessed_hook_events.sql
@@ -0,0 +1,11 @@
+-- Deploy guix-build-coordinator:unprocessed_hook_events to sqlite
+
+BEGIN;
+
+CREATE TABLE unprocessed_hook_events (
+ id INTEGER PRIMARY KEY ASC,
+ event TEXT NOT NULL,
+ arguments TEXT NOT NULL
+);
+
+COMMIT;
diff --git a/sqitch/sqlite/revert/unprocessed_hook_events.sql b/sqitch/sqlite/revert/unprocessed_hook_events.sql
new file mode 100644
index 0000000..4a3137d
--- /dev/null
+++ b/sqitch/sqlite/revert/unprocessed_hook_events.sql
@@ -0,0 +1,7 @@
+-- Revert guix-build-coordinator:unprocessed_hook_events from sqlite
+
+BEGIN;
+
+-- XXX Add DDLs here.
+
+COMMIT;
diff --git a/sqitch/sqlite/verify/unprocessed_hook_events.sql b/sqitch/sqlite/verify/unprocessed_hook_events.sql
new file mode 100644
index 0000000..0a5fb28
--- /dev/null
+++ b/sqitch/sqlite/verify/unprocessed_hook_events.sql
@@ -0,0 +1,7 @@
+-- Verify guix-build-coordinator:unprocessed_hook_events on sqlite
+
+BEGIN;
+
+-- XXX Add verifications here.
+
+ROLLBACK;