mirror of
https://github.com/TeamPiped/Piped-Backend.git
synced 2024-08-14 23:51:41 +00:00
Add check for database session in healthcheck. (#232)
* Add check for database session in healthcheck. * Add curl test for healthcheck.
This commit is contained in:
parent
6376401d98
commit
5b6dc2b097
2 changed files with 10 additions and 1 deletions
|
@ -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"))))
|
||||||
|
|
|
@ -3,6 +3,9 @@
|
||||||
CURLOPTS=(-i -s -S -o /dev/null -f -w "%{http_code}\tTime:\t%{time_starttransfer}\t%{url_effective}\n")
|
CURLOPTS=(-i -s -S -o /dev/null -f -w "%{http_code}\tTime:\t%{time_starttransfer}\t%{url_effective}\n")
|
||||||
HOST=127.0.0.1:8080
|
HOST=127.0.0.1:8080
|
||||||
|
|
||||||
|
# Healthcheck Test
|
||||||
|
curl ${CURLOPTS[@]} $HOST/healthcheck || exit 1
|
||||||
|
|
||||||
# Version Test
|
# Version Test
|
||||||
curl ${CURLOPTS[@]} $HOST/version || exit 1
|
curl ${CURLOPTS[@]} $HOST/version || exit 1
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue