aboutsummaryrefslogtreecommitdiff
path: root/guix-build-coordinator/datastore.scm
blob: 24b9bbb28c0679f07776a79240425292de81ad38 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
(define-module (guix-build-coordinator datastore)
  #:use-module (srfi srfi-1)
  #:use-module (oop goops)
  #:use-module (guix-build-coordinator datastore abstract)
  #:use-module (guix-build-coordinator datastore sqlite)
  #:use-module (guix-build-coordinator datastore postgresql)
  #:duplicates (merge-generics)
  #:export (database-uri->datastore
            datastore-find-build-output))

(re-export datastore-spawn-fibers)
(re-export datastore-initialise-metrics!)
(re-export datastore-update-metrics!)
(re-export datastore-update)
(re-export datastore-call-with-transaction)
(re-export datastore-store-derivation)
(re-export datastore-insert-build)
(re-export datastore-cancel-build)
(re-export datastore-new-agent)
(re-export datastore-list-agents)
(re-export datastore-find-agent)
(re-export datastore-fetch-agent-tags)
(re-export datastore-count-build-results)
(re-export datastore-insert-build-result)
(re-export datastore-remove-build-allocation)
(re-export datastore-mark-build-as-processed)
(re-export datastore-delete-relevant-outputs-from-unbuilt-outputs)
(re-export datastore-store-output-metadata)
(re-export datastore-store-build-start)
(re-export datastore-find-build-starts)
(re-export datastore-count-setup-failures)
(re-export datastore-list-setup-failures-for-build)
(re-export datastore-fetch-setup-failures)
(re-export datastore-list-unbuilt-derivation-outputs)
(re-export datastore-list-build-outputs)
(re-export datastore-list-related-derivations-with-no-build-for-outputs)
(re-export datastore-list-failed-builds-with-blocking-count)
(re-export datastore-list-builds-for-derivation-recursive-inputs)
(re-export datastore-store-setup-failure)
(re-export datastore-store-setup-failure/missing-inputs)
(re-export datastore-list-setup-failure-missing-inputs)
(re-export datastore-new-agent-password)
(re-export datastore-agent-password-exists?)
(re-export datastore-replace-agent-tags)
(re-export datastore-count-builds)
(re-export datastore-for-each-build)
(re-export datastore-find-build)
(re-export datastore-list-builds)
(re-export datastore-insert-build-tags)
(re-export datastore-fetch-build-tags)
(re-export datastore-find-build-result)
(re-export datastore-find-build-derivation-system)
(re-export datastore-count-builds-for-derivation)
(re-export datastore-list-processed-builds)
(re-export datastore-list-unprocessed-builds)
(re-export datastore-find-first-unallocated-deferred-build)
(re-export datastore-fetch-build-ids-and-propagated-priorities-for-unprocessed-builds)
(re-export datastore-insert-unprocessed-hook-event)
(re-export datastore-count-unprocessed-hook-events)
(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)
(re-export datastore-find-derivation-outputs)
(re-export datastore-find-derivation-system)
(re-export datastore-find-derivation-inputs)
(re-export datastore-find-derivation-for-output)
(re-export datastore-list-builds-for-output)
(re-export datastore-list-builds-for-output-and-system)
(re-export datastore-agent-for-build)
(re-export datastore-count-build-allocation-plan-entries)
(re-export datastore-replace-build-allocation-plan)
(re-export datastore-remove-build-from-allocation-plan)
(re-export datastore-count-allocated-builds)
(re-export datastore-agent-requested-systems)
(re-export datastore-update-agent-requested-systems)
(re-export datastore-fetch-build-to-allocate)
(re-export datastore-insert-to-allocated-builds)
(re-export datastore-remove-builds-from-plan)
(re-export datastore-select-allocated-builds)
(re-export datastore-list-allocation-plan-builds)

(define* (database-uri->datastore database
                                  #:key
                                  metrics-registry)
  (cond
   ((string-prefix? "pg://" database)
    (postgresql-datastore database))
   ((string-prefix? "sqlite://" database)
    (sqlite-datastore database #:metrics-registry metrics-registry))
   (else
    (error
     (simple-format #f "Unknown database ~A" database)))))

(define (datastore-find-build-output datastore build-id output-name)
  (let* ((build (datastore-find-build datastore build-id))
         (outputs (datastore-find-derivation-outputs
                   datastore
                   (assq-ref build 'derivation-name))))
    (any (lambda (output)
           (if (string=? (assq-ref output 'name) output-name)
               (assq-ref output 'output)
               #f))
         outputs)))