aboutsummaryrefslogtreecommitdiff
path: root/guix-build-coordinator/datastore.scm
blob: 83609707f5338579272b1b5cfb5b3e7a6a635f2e (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
(define-module (guix-build-coordinator datastore)
  #:use-module (srfi srfi-1)
  #:use-module (oop goops)
  #:duplicates (merge-generics)
  #: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
               datastore-store-build
               datastore-new-agent
               datastore-list-agents
               datastore-find-agent
               datastore-store-build-result
               datastore-new-agent-password
               datastore-agent-password-exists?
               datastore-find-build
               datastore-list-unprocessed-builds
               datastore-list-agent-builds
               datastore-find-derivation-outputs
               datastore-agent-for-build
               datastore-replace-build-allocation-plan
               datastore-allocate-builds-to-agent
               datastore-list-allocation-plan-builds)
  #:export (database-uri->datastore
            datastore-find-build-output))

(define (database-uri->datastore database)
  (cond
   ((string-prefix? "pg://" database)
    (postgresql-datastore database))
   ((string-prefix? "sqlite://" database)
    (sqlite-datastore database))
   (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)
           (when (string=? (assq-ref output 'name) output-name)
             (assq-ref output 'output)))
         outputs)))