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:
parent
aad2c9d9e8
commit
33cf8d66f6
1 changed files with 22 additions and 1 deletions
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue