Skip to content
Snippets Groups Projects
Unverified Commit 74c1a94a authored by Mathieu Othacehe's avatar Mathieu Othacehe
Browse files

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.
parent 158966dc
No related branches found
No related tags found
No related merge requests found
......@@ -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 \
......
......@@ -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))
......
......@@ -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,
......
BEGIN TRANSACTION;
ALTER TABLE Builds ADD COLUMN last_status INTEGER,
COMMIT;
......@@ -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;"))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment