aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Baines <mail@cbaines.net>2019-06-06 21:08:34 +0100
committerChristopher Baines <mail@cbaines.net>2019-06-06 21:08:34 +0100
commit33cf8d66f6076d0690f286eea7084a36417a6cb2 (patch)
tree970a58dc2218f359c53a5ddc1f046e645d81c0bf
parentaad2c9d9e835d7af362febae9bf3cb7bf6225c6b (diff)
downloaddata-service-33cf8d66f6076d0690f286eea7084a36417a6cb2.tar
data-service-33cf8d66f6076d0690f286eea7084a36417a6cb2.tar.gz
Add a healthcheck endpoint
This indicates currently if the database is accessible and a simple query can be performed. I'm mostly looking at using this when writing a system test for this service.
-rw-r--r--guix-data-service/web/controller.scm23
1 files changed, 22 insertions, 1 deletions
diff --git a/guix-data-service/web/controller.scm b/guix-data-service/web/controller.scm
index c06b24c..bc489b5 100644
--- a/guix-data-service/web/controller.scm
+++ b/guix-data-service/web/controller.scm
@@ -544,7 +544,28 @@
(or (render-static-asset (string-join rest "/")
(request-headers request))
(not-found (request-uri request))))
-
+ ((GET "healthcheck")
+ (let ((database-status
+ (catch
+ #t
+ (lambda ()
+ (with-postgresql-connection
+ (lambda (conn)
+ (number?
+ (string->number
+ (first
+ (count-guix-revisions conn)))))))
+ (lambda (key . args)
+ (peek key args)
+ #f))))
+ (render-json
+ `((status . ,(if database-status
+ "ok"
+ "not ok")))
+ #:code (if (eq? database-status
+ #t)
+ 200
+ 500))))
(_
(with-postgresql-connection
(lambda (conn)