From 33cf8d66f6076d0690f286eea7084a36417a6cb2 Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Thu, 6 Jun 2019 21:08:34 +0100 Subject: [PATCH] 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. --- guix-data-service/web/controller.scm | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) 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)