database: Add "db-get-build-percentage".
* src/cuirass/database.scm (db-get-build-percentage): New procedure. * tests/database.scm ("db-get-build-percentage"): New test.
This commit is contained in:
parent
1271b11725
commit
213683ad27
|
@ -64,6 +64,7 @@
|
|||
db-get-output
|
||||
db-get-outputs
|
||||
db-get-time-since-previous-build
|
||||
db-get-build-percentage
|
||||
db-register-builds
|
||||
db-update-build-status!
|
||||
db-update-build-worker!
|
||||
|
@ -667,6 +668,25 @@ WHERE job_name = " job-name "AND specification = " specification
|
|||
(string->number time))
|
||||
(else #f))))
|
||||
|
||||
(define (db-get-build-percentage build-id)
|
||||
"Return the build completion percentage for BUILD-ID."
|
||||
(with-db-worker-thread db
|
||||
(match (expect-one-row
|
||||
(exec-query/bind db "
|
||||
SELECT LEAST(duration::float/last_duration * 100, 100)::int AS percentage FROM
|
||||
(SELECT (extract(epoch from now())::int - starttime) as duration,
|
||||
last_build.duration AS last_duration FROM builds,
|
||||
(SELECT (stoptime - starttime) AS duration FROM Builds
|
||||
WHERE job_name IN
|
||||
(SELECT job_name from Builds WHERE id = " build-id ")
|
||||
AND status = 0
|
||||
ORDER BY Builds.timestamp DESC LIMIT 1) last_build
|
||||
where id = " build-id ") d;
|
||||
"))
|
||||
((time)
|
||||
(string->number time))
|
||||
(else #f))))
|
||||
|
||||
(define (db-register-builds jobs eval-id specification)
|
||||
(define (new-outputs? outputs)
|
||||
(let ((new-outputs
|
||||
|
|
|
@ -402,6 +402,37 @@ timestamp, checkouttime, evaltime) VALUES ('guix', 0, 0, 0, 0);")
|
|||
#:outputs `(("out" . "/bar"))))
|
||||
(sort (db-get-pending-derivations) string<?)))
|
||||
|
||||
(test-assert "db-get-build-percentage"
|
||||
(begin
|
||||
(let* ((ts (time-second (current-time time-utc)))
|
||||
(old `((#:derivation . "/last.drv")
|
||||
(#:eval-id . 2)
|
||||
(#:job-name . "job")
|
||||
(#:timestamp . ,(- ts 10))
|
||||
(#:status . 0)
|
||||
(#:starttime . 10)
|
||||
(#:stoptime . 20)
|
||||
(#:system . "x86_64-linux")
|
||||
(#:nix-name . "foo")
|
||||
(#:log . "log")
|
||||
(#:outputs . ())))
|
||||
(new `((#:derivation . "/cur.drv")
|
||||
(#:eval-id . 2)
|
||||
(#:job-name . "job")
|
||||
(#:timestamp . ,(- ts 5))
|
||||
(#:starttime . ,(- ts 5))
|
||||
(#:system . "x86_64-linux")
|
||||
(#:nix-name . "foo")
|
||||
(#:log . "log")
|
||||
(#:outputs . ()))))
|
||||
(db-add-build old)
|
||||
(db-add-build new)
|
||||
(let ((last-id
|
||||
(match (expect-one-row
|
||||
(exec-query (%db) "SELECT MAX(id) FROM Builds;"))
|
||||
((id) (string->number id)))))
|
||||
(>= (db-get-build-percentage last-id) 50)))))
|
||||
|
||||
(test-assert "db-close"
|
||||
(begin
|
||||
(exec-query (%db) (format #f "DROP OWNED BY CURRENT_USER;"))
|
||||
|
|
Loading…
Reference in New Issue