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.
This commit is contained in:
Christopher Baines 2019-06-06 21:08:34 +01:00
parent aad2c9d9e8
commit 33cf8d66f6

View file

@ -544,7 +544,28 @@
(or (render-static-asset (string-join rest "/") (or (render-static-asset (string-join rest "/")
(request-headers request)) (request-headers request))
(not-found (request-uri 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 (with-postgresql-connection
(lambda (conn) (lambda (conn)