guix-commits
[Top][All Lists]
Advanced

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

branch master updated: Add periodical build support.


From: Mathieu Othacehe
Subject: branch master updated: Add periodical build support.
Date: Wed, 25 Nov 2020 04:44:53 -0500

This is an automated email from the git hooks/post-receive script.

mothacehe pushed a commit to branch master
in repository guix-cuirass.

The following commit(s) were added to refs/heads/master by this push:
     new 053f922  Add periodical build support.
053f922 is described below

commit 053f92273a09784cf3a9ee3ac0c79a30a42c6df4
Author: Mathieu Othacehe <othacehe@gnu.org>
AuthorDate: Tue Nov 24 17:54:31 2020 +0100

    Add periodical build support.
    
    * src/cuirass/database.scm (db-get-time-since-previous-build): New 
procedure,
    (db-register-builds): if the period argument is set, only register builds
    which last registration is older than the specified period.
---
 src/cuirass/database.scm | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)

diff --git a/src/cuirass/database.scm b/src/cuirass/database.scm
index fc3eb00..94060b7 100644
--- a/src/cuirass/database.scm
+++ b/src/cuirass/database.scm
@@ -64,6 +64,7 @@
             db-get-inputs
             db-get-build
             db-get-builds
+            db-get-time-since-previous-build
             db-get-builds-by-search
             db-get-builds-min
             db-get-builds-max
@@ -713,6 +714,7 @@ path) VALUES ("
            (system   (assq-ref job #:system))
            (nix-name (assq-ref job #:nix-name))
            (log      (assq-ref job #:log))
+           (period   (assq-ref job #:period))
            (outputs  (assq-ref job #:outputs))
            (cur-time (time-second (current-time time-utc))))
       (and (new-outputs? outputs)
@@ -731,7 +733,14 @@ path) VALUES ("
                           (#:timestamp . ,cur-time)
                           (#:starttime . 0)
                           (#:stoptime . 0))))
-             (db-add-build build)))))
+             (if period
+                 (let* ((time (db-get-time-since-previous-build job-name))
+                        (add-build? (cond
+                                     ((not time) #t)
+                                     ((> time period) #t)
+                                     (else #f))))
+                   (and add-build? (db-add-build build)))
+                 (db-add-build build))))))
 
   ;; Use the database worker dedicated to write queries.  We don't want this
   ;; query to be queued as it is already a quite large transaction by itself,
@@ -1073,6 +1082,16 @@ ORDER BY ~a;"
     (let ((key (if (number? derivation-or-id) 'id 'derivation)))
       (expect-one-row (db-get-builds `((,key . ,derivation-or-id)))))))
 
+(define (db-get-time-since-previous-build job-name)
+  "Return the time difference in seconds between the current time and the
+registration time of the last build for JOB-NAME."
+  (with-db-worker-thread db
+    (let ((rows (sqlite-exec db "
+SELECT strftime('%s', 'now') - timestamp FROM Builds
+WHERE job_name  = " job-name
+"ORDER BY timestamp DESC LIMIT 1")))
+      (and=> (expect-one-row rows) (cut vector-ref <> 0)))))
+
 (define (db-add-event type timestamp details)
   (when (%record-events?)
     (with-db-writer-worker-thread db



reply via email to

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