From fd432b8e8f449d691773e96e7d90f44761e01aa3 Mon Sep 17 00:00:00 2001 From: Mathieu Othacehe Date: Wed, 25 Nov 2020 15:49:04 +0100 Subject: Use specification for periodic builds. When the periodic argument is passed to a job, it will be registered only if the time difference between the current time and the registration time of the last build is greater than the specified period. Make sure that the last job that is searched is part of the same specification. * src/sql/upgrade-16.sql: New file. * Makefile.am (dist_sql_DATA): Add it. * src/schema.sql (Builds_job_name_timestamp): New index. * src/cuirass/database.scm (db-get-time-since-previous-build): Add "specification" argument, (db-register-builds): pass it. --- Makefile.am | 3 ++- src/cuirass/database.scm | 15 +++++++++------ src/schema.sql | 1 + src/sql/upgrade-16.sql | 5 +++++ 4 files changed, 17 insertions(+), 7 deletions(-) create mode 100644 src/sql/upgrade-16.sql diff --git a/Makefile.am b/Makefile.am index 98f89f9..17a73f0 100644 --- a/Makefile.am +++ b/Makefile.am @@ -84,7 +84,8 @@ dist_sql_DATA = \ src/sql/upgrade-12.sql \ src/sql/upgrade-13.sql \ src/sql/upgrade-14.sql \ - src/sql/upgrade-15.sql + src/sql/upgrade-15.sql \ + src/sql/upgrade-16.sql dist_css_DATA = \ src/static/css/cuirass.css \ diff --git a/src/cuirass/database.scm b/src/cuirass/database.scm index 94060b7..9b17c67 100644 --- a/src/cuirass/database.scm +++ b/src/cuirass/database.scm @@ -734,7 +734,9 @@ path) VALUES (" (#:starttime . 0) (#:stoptime . 0)))) (if period - (let* ((time (db-get-time-since-previous-build job-name)) + (let* ((spec (db-get-evaluation-specification eval-id)) + (time + (db-get-time-since-previous-build job-name spec)) (add-build? (cond ((not time) #t) ((> time period) #t) @@ -1082,14 +1084,15 @@ 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) +(define (db-get-time-since-previous-build job-name specification) "Return the time difference in seconds between the current time and the -registration time of the last build for JOB-NAME." +registration time of the last build for JOB-NAME and SPECIFICATION." (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"))) +SELECT strftime('%s', 'now') - Builds.timestamp FROM Builds +INNER JOIN Evaluations on Builds.evaluation = Evaluations.id +WHERE job_name = " job-name "AND specification = " specification +"ORDER BY Builds.timestamp DESC LIMIT 1"))) (and=> (expect-one-row rows) (cut vector-ref <> 0))))) (define (db-add-event type timestamp details) diff --git a/src/schema.sql b/src/schema.sql index 1eeac80..6b08b7e 100644 --- a/src/schema.sql +++ b/src/schema.sql @@ -99,6 +99,7 @@ CREATE TABLE Events ( -- an index. It is also preferable for the other tables. CREATE INDEX Builds_status_index ON Builds (status); CREATE INDEX Builds_evaluation_index ON Builds (evaluation, status); +CREATE INDEX Builds_job_name_timestamp on Builds(job_name, timestamp); CREATE INDEX Builds_nix_name ON Builds (nix_name COLLATE NOCASE); CREATE INDEX Builds_timestamp_stoptime on Builds(timestamp, stoptime); CREATE INDEX Builds_stoptime on Builds(stoptime DESC); diff --git a/src/sql/upgrade-16.sql b/src/sql/upgrade-16.sql new file mode 100644 index 0000000..47d498c --- /dev/null +++ b/src/sql/upgrade-16.sql @@ -0,0 +1,5 @@ +BEGIN TRANSACTION; + +CREATE INDEX Builds_job_name_timestamp on Builds(job_name, timestamp); + +COMMIT; -- cgit v1.2.3