Add check for database session in healthcheck.

This commit is contained in:
Kavin 2022-03-29 09:43:38 +01:00
parent 6376401d98
commit d4c6383d55
No known key found for this signature in database
GPG key ID: 49451E4482CC5BCD

View file

@ -44,7 +44,13 @@ public class ServerLauncher extends MultithreadedHttpServerLauncher {
AsyncServlet mainServlet(Executor executor) { AsyncServlet mainServlet(Executor executor) {
RoutingServlet router = RoutingServlet.create() RoutingServlet router = RoutingServlet.create()
.map(GET, "/healthcheck", request -> getRawResponse("OK".getBytes(UTF_8), "text/plain", "no-store")) .map(GET, "/healthcheck", AsyncServlet.ofBlocking(executor, request -> {
try (Session ignored = DatabaseSessionFactory.createSession()) {
return getRawResponse("OK".getBytes(UTF_8), "text/plain", "no-store");
} catch (Exception e) {
return getErrorResponse(e, request.getPath());
}
}))
.map(GET, "/version", AsyncServlet.ofBlocking(executor, request -> getRawResponse(Constants.VERSION.getBytes(UTF_8), "text/plain", "no-store"))) .map(GET, "/version", AsyncServlet.ofBlocking(executor, request -> getRawResponse(Constants.VERSION.getBytes(UTF_8), "text/plain", "no-store")))
.map(HttpMethod.OPTIONS, "/*", request -> HttpResponse.ofCode(200)) .map(HttpMethod.OPTIONS, "/*", request -> HttpResponse.ofCode(200))
.map(GET, "/webhooks/pubsub", request -> HttpResponse.ok200().withPlainText(Objects.requireNonNull(request.getQueryParameter("hub.challenge")))) .map(GET, "/webhooks/pubsub", request -> HttpResponse.ok200().withPlainText(Objects.requireNonNull(request.getQueryParameter("hub.challenge"))))