guix-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[no subject]


From: Mathieu Othacehe
Date: Mon, 19 Apr 2021 13:38:46 -0400 (EDT)

branch: master
commit cc138fd8c5f2783901d76601d94744528a830cf5
Author: Mathieu Othacehe <othacehe@gnu.org>
AuthorDate: Sun Apr 18 18:54:01 2021 +0200

    Add "db-get-previous-eval" and "db-get-next-eval" procedures.
    
    * src/cuirass/database.scm (db-get-previous-eval, db-get-next-eval): New
    procedures.
    * tests/database.scm ("db-get-previous-eval", "db-get-next-eval"): New 
tests.
---
 src/cuirass/database.scm | 28 ++++++++++++++++++++++++++++
 tests/database.scm       |  7 +++++++
 2 files changed, 35 insertions(+)

diff --git a/src/cuirass/database.scm b/src/cuirass/database.scm
index e140819..d04a60a 100644
--- a/src/cuirass/database.scm
+++ b/src/cuirass/database.scm
@@ -89,6 +89,8 @@
             db-get-evaluation
             db-get-evaluations
             db-get-evaluations-build-summary
+            db-get-previous-eval
+            db-get-next-eval
             db-get-evaluations-id-min
             db-get-evaluations-id-max
             db-get-latest-evaluations
@@ -1367,6 +1369,32 @@ ORDER BY E.id DESC;")
                          (#:scheduled . ,(or (string->number scheduled) 0)))
                        evaluations))))))))
 
+(define (db-get-previous-eval eval-id)
+  "Return the successful evaluation preceeding EVAL-ID, for the same
+specification."
+  (with-db-worker-thread db
+    (match (expect-one-row
+            (exec-query/bind db "
+SELECT id FROM Evaluations WHERE id < " eval-id
+"AND specification =
+(SELECT specification FROM Evaluations WHERE id = " eval-id
+") AND status = 0 ORDER BY id DESC LIMIT 1;"))
+      ((id) (and id (string->number id)))
+      (else #f))))
+
+(define (db-get-next-eval eval-id)
+  "Return the successful evaluation succeeding EVAL-ID, for the same
+specification."
+  (with-db-worker-thread db
+    (match (expect-one-row
+            (exec-query/bind db "
+SELECT id FROM Evaluations WHERE id > " eval-id
+"AND specification =
+(SELECT specification FROM Evaluations WHERE id = " eval-id
+") AND status = 0 ORDER BY id ASC LIMIT 1;"))
+      ((id) (and id (string->number id)))
+      (else #f))))
+
 (define (db-get-evaluations-id-min spec)
   "Return the min id of evaluations for the given specification SPEC."
   (with-db-worker-thread db
diff --git a/tests/database.scm b/tests/database.scm
index 5bf59db..1229ac6 100644
--- a/tests/database.scm
+++ b/tests/database.scm
@@ -227,6 +227,13 @@ timestamp, checkouttime, evaltime) VALUES ('guix', 0, 0, 
0, 0);")
                                ("foo2" . "/test.drv.output.2")))))
                           4 (db-get-specification "guix"))))
 
+  (test-equal "db-get-previous-eval"
+    1
+    (db-get-previous-eval 4))
+
+  (test-assert "db-get-next-eval"
+    (not (db-get-next-eval 3)))
+
   (test-assert "db-get-jobs same-outputs"
     (match (db-get-jobs 4 '())
       ((job)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]