[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
branch master updated: Introduce build "last_status" field.
From: |
Mathieu Othacehe |
Subject: |
branch master updated: Introduce build "last_status" field. |
Date: |
Mon, 01 Feb 2021 05:47:15 -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 74c1a94 Introduce build "last_status" field.
74c1a94 is described below
commit 74c1a94a4db41ae1bebc4fe7dd7e2f550eb7e46f
Author: Mathieu Othacehe <othacehe@gnu.org>
AuthorDate: Mon Feb 1 11:44:35 2021 +0100
Introduce build "last_status" field.
* src/sql/upgrade-3.sql: New file.
* Makefile.am (dist_sql_DATA): Add it.
* src/schema.sql (Builds)[last_status]: New field.
* src/cuirass/database.scm (db-update-build-status!): Honor it.
(db-get-builds): Return it.
* tests/database.scm ("db-update-build-status!"): New test.
---
Makefile.am | 3 ++-
src/cuirass/database.scm | 31 +++++++++++++++++++++++--------
src/schema.sql | 1 +
src/sql/upgrade-3.sql | 5 +++++
tests/database.scm | 25 ++++++++++++++++++++++---
5 files changed, 53 insertions(+), 12 deletions(-)
diff --git a/Makefile.am b/Makefile.am
index e5de6d3..dacc753 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -80,7 +80,8 @@ dist_pkgdata_DATA = src/schema.sql
dist_sql_DATA = \
src/sql/upgrade-1.sql \
- src/sql/upgrade-2.sql
+ src/sql/upgrade-2.sql \
+ src/sql/upgrade-3.sql
dist_css_DATA = \
src/static/css/cuirass.css \
diff --git a/src/cuirass/database.scm b/src/cuirass/database.scm
index 74e73bc..9903299 100644
--- a/src/cuirass/database.scm
+++ b/src/cuirass/database.scm
@@ -788,13 +788,25 @@ log file for DRV."
;; Update only if we're switching to a different status; otherwise
;; leave things unchanged. This ensures that 'stoptime' remains valid
;; and doesn't change every time we mark DRV as 'succeeded' several
- ;; times in a row, for instance.
+ ;; times in a row, for instance. The 'last_status' field is updated
+ ;; with the status of the last completed build with the same
+ ;; 'job_name' and 'specification'.
(begin
(let ((rows
- (exec-query/bind db "UPDATE Builds SET stoptime=" now
- ", status=" status
- "WHERE derivation=" drv
- " AND status != " status ";")))
+ (exec-query/bind db "
+UPDATE Builds SET stoptime =" now
+", status =" status
+", last_status =
+(SELECT Builds.status FROM (SELECT job_name, specification FROM Builds
+INNER JOIN Evaluations ON Builds.evaluation = Evaluations.id WHERE
+derivation = " drv ") AS cur, Builds INNER JOIN
+Evaluations ON Builds.evaluation = Evaluations.id
+WHERE cur.job_name = Builds.job_name AND
+cur.specification = Evaluations.specification AND
+Builds.status >= 0
+ORDER BY evaluation DESC LIMIT 1)
+WHERE derivation =" drv
+" AND status != " status ";")))
(when (positive? rows)
(db-add-event 'build
now
@@ -1014,8 +1026,9 @@ OR :borderhightime IS NULL OR :borderhighid IS NULL)")))
(string-join rest " AND ")))))
(query
(format #f " SELECT Builds.derivation, Builds.id, Builds.timestamp,
-Builds.starttime, Builds.stoptime, Builds.log, Builds.status, Builds.priority,
-Builds.max_silent, Builds.timeout, Builds.job_name, Builds.system,
+Builds.starttime, Builds.stoptime, Builds.log, Builds.status,
+Builds.last_status, Builds.priority, Builds.max_silent,
+Builds.timeout, Builds.job_name, Builds.system,
Builds.worker, Builds.nix_name, Builds.evaluation, agg.name, agg.outputs_name,
agg.outputs_path,agg.bp_build, agg.bp_type, agg.bp_file_size,
agg.bp_checksum, agg.bp_path
@@ -1063,7 +1076,7 @@ ORDER BY ~a;"
(match builds
(() (reverse result))
(((derivation id timestamp starttime stoptime log status
- priority max-silent timeout job-name
+ last-status priority max-silent timeout job-name
system worker nix-name eval-id specification
outputs-name outputs-path
products-id products-type products-file-size
@@ -1077,6 +1090,8 @@ ORDER BY ~a;"
(#:stoptime . ,(string->number stoptime))
(#:log . ,log)
(#:status . ,(string->number status))
+ (#:last-status . ,(and last-status
+ (string->number last-status)))
(#:priority . ,(string->number priority))
(#:max-silent . ,(string->number max-silent))
(#:timeout . ,(string->number timeout))
diff --git a/src/schema.sql b/src/schema.sql
index 70b945a..1cfdae4 100644
--- a/src/schema.sql
+++ b/src/schema.sql
@@ -63,6 +63,7 @@ CREATE TABLE Builds (
nix_name TEXT NOT NULL,
log TEXT NOT NULL,
status INTEGER NOT NULL,
+ last_status INTEGER,
priority INTEGER NOT NULL DEFAULT 0,
max_silent INTEGER NOT NULL DEFAULT 0,
timeout INTEGER NOT NULL DEFAULT 0,
diff --git a/src/sql/upgrade-3.sql b/src/sql/upgrade-3.sql
new file mode 100644
index 0000000..c6e9f19
--- /dev/null
+++ b/src/sql/upgrade-3.sql
@@ -0,0 +1,5 @@
+BEGIN TRANSACTION;
+
+ALTER TABLE Builds ADD COLUMN last_status INTEGER,
+
+COMMIT;
diff --git a/tests/database.scm b/tests/database.scm
index 08f2fd1..7fde88b 100644
--- a/tests/database.scm
+++ b/tests/database.scm
@@ -64,11 +64,13 @@
(define* (make-dummy-build drv
#:optional (eval-id 2)
- #:key (outputs
- `(("foo" . ,(format #f "~a.output" drv)))))
+ #:key
+ (job-name "job")
+ (outputs
+ `(("foo" . ,(format #f "~a.output" drv)))))
`((#:derivation . ,drv)
(#:eval-id . ,eval-id)
- (#:job-name . "job")
+ (#:job-name . ,job-name)
(#:timestamp . ,(time-second (current-time time-utc)))
(#:system . "x86_64-linux")
(#:nix-name . "foo")
@@ -445,6 +447,23 @@ timestamp, checkouttime, evaltime) VALUES ('guix', 0, 0,
0, 0);")
((id) (string->number id)))))
(>= (db-get-build-percentage last-id) 50)))))
+ (test-equal "db-update-build-status!"
+ (list #f 1)
+ (begin
+ (db-add-evaluation "guix"
+ (make-dummy-checkouts "fakesha5" "fakesha6"))
+ (db-add-build (make-dummy-build "/old-build.drv" 3
+ #:job-name "job-1"
+ #:outputs `(("out" . "/old"))))
+ (db-add-build (make-dummy-build "/new-build.drv" 4
+ #:job-name "job-1"
+ #:outputs `(("out" . "/new"))))
+ (db-update-build-status! "/old-build.drv" 1)
+ (db-update-build-status! "/new-build.drv" 0)
+ (map (cut assq-ref <> #:last-status)
+ (list (db-get-build "/old-build.drv")
+ (db-get-build "/new-build.drv")))))
+
(test-assert "db-close"
(begin
(exec-query (%db) (format #f "DROP OWNED BY CURRENT_USER;"))
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- branch master updated: Introduce build "last_status" field.,
Mathieu Othacehe <=