branch: main
commit 878af4946d7765d36e864543f43ff72029847b61
Author: Ludovic Courtès <[email protected]>
AuthorDate: Sun Jan 5 17:25:25 2025 +0100
metrics: Add #:timestamp to ‘db-update-metric’.
* src/cuirass/metrics.scm (db-update-metric): Add #:timestamp parameter
and honor it.
---
src/cuirass/metrics.scm | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/src/cuirass/metrics.scm b/src/cuirass/metrics.scm
index 3c21b27..e4c6cf5 100644
--- a/src/cuirass/metrics.scm
+++ b/src/cuirass/metrics.scm
@@ -402,16 +402,16 @@ WHERE type = :type ORDER BY ~a LIMIT ~a" order limit))
`((,field . ,(locale-string->inexact value))
,@metrics))))))))))
-(define* (db-update-metric id #:optional field)
- "Compute and update the value of the metric ID in database.
+(define* (db-update-metric id #:optional field
+ #:key
+ (timestamp (time-second (current-time time-utc))))
+ "Compute and update the value of the metric ID in database with the given
+TIMESTAMP.
FIELD is optional and can be the id of a database object such as an
evaluation or a specification that the METRIC applies to. If FIELD is not
passed then the METRIC may provide a FIELD-PROC to compute it. It is useful
for periodical metrics for instance."
- (define now
- (time-second (current-time time-utc)))
-
(with-db-connection db
(let* ((metric (find-metric id))
(field-proc (metric-field-proc metric))
@@ -425,9 +425,9 @@ for periodical metrics for instance."
INSERT INTO Metrics (field, type, value, timestamp) VALUES ("
field ", " (metric->type metric) ", "
value ", "
- now ")
+ timestamp ")
ON CONFLICT ON CONSTRAINT metrics_pkey DO
-UPDATE SET value = " value ", timestamp = " now ";"))
+UPDATE SET value = " value ", timestamp = " timestamp ";"))
(log-warning "failed to compute metric ~a (~a)"
(symbol->string id) field)))))