From c53542122458b251d6df4e919aab5de589da6781 Mon Sep 17 00:00:00 2001 From: Joakim Taule Kartveit Date: Tue, 15 Oct 2024 13:37:00 +0200 Subject: [PATCH] chore: drop restart application on error (#263) --- src/main/kotlin/no/nav/pdfgen/Application.kt | 8 +++----- src/main/kotlin/no/nav/pdfgen/plugins/LifecycleHooks.kt | 9 +++++++-- src/main/kotlin/no/nav/pdfgen/plugins/StatusPages.kt | 5 +---- src/main/resources/logback.xml | 3 +-- 4 files changed, 12 insertions(+), 13 deletions(-) diff --git a/src/main/kotlin/no/nav/pdfgen/Application.kt b/src/main/kotlin/no/nav/pdfgen/Application.kt index a7ee4f0..a10eb7d 100644 --- a/src/main/kotlin/no/nav/pdfgen/Application.kt +++ b/src/main/kotlin/no/nav/pdfgen/Application.kt @@ -1,7 +1,5 @@ package no.nav.pdfgen -// Uncommemt to enable debug to file -// import java.io.File import com.openhtmltopdf.slf4j.Slf4jLogger import com.openhtmltopdf.util.XRLog import io.ktor.server.application.* @@ -50,10 +48,10 @@ fun Application.module() { val templates = coreEnvironment.templates XRLog.setLoggerImpl(Slf4jLogger()) - configureLifecycleHooks(applicationState) + configureLifecycleHooks(applicationState = applicationState) configureContentNegotiation() - configureStatusPages(templates, applicationState) - configureNais(applicationState) + configureStatusPages(templates = templates) + configureNais(applicationState = applicationState) configureReloadPDFGenCore(environment = environment) configureRouting(environment = environment) } diff --git a/src/main/kotlin/no/nav/pdfgen/plugins/LifecycleHooks.kt b/src/main/kotlin/no/nav/pdfgen/plugins/LifecycleHooks.kt index 0a2da0d..c4b3784 100644 --- a/src/main/kotlin/no/nav/pdfgen/plugins/LifecycleHooks.kt +++ b/src/main/kotlin/no/nav/pdfgen/plugins/LifecycleHooks.kt @@ -5,6 +5,11 @@ import no.nav.pdfgen.ApplicationState fun Application.configureLifecycleHooks(applicationState: ApplicationState) { - this.monitor.subscribe(ApplicationStarted) { applicationState.ready = true } - this.monitor.subscribe(ApplicationStopped) { applicationState.ready = false } + monitor.subscribe(ApplicationStarted) { + applicationState.ready = true + } + monitor.subscribe(ApplicationStopped) { + applicationState.ready = false + applicationState.alive = false + } } diff --git a/src/main/kotlin/no/nav/pdfgen/plugins/StatusPages.kt b/src/main/kotlin/no/nav/pdfgen/plugins/StatusPages.kt index 6f3b7e7..b495129 100644 --- a/src/main/kotlin/no/nav/pdfgen/plugins/StatusPages.kt +++ b/src/main/kotlin/no/nav/pdfgen/plugins/StatusPages.kt @@ -12,14 +12,11 @@ import no.nav.pdfgen.logger fun Application.configureStatusPages( templates: Map, Template>, - applicationState: ApplicationState ) { install(StatusPages) { exception { call, cause -> - call.respond(HttpStatusCode.InternalServerError, cause.message ?: "Unknown error") logger.error("Caught exception", cause) - applicationState.alive = false - applicationState.ready = false + call.respond(HttpStatusCode.InternalServerError, cause.message ?: "Unknown error") } status(HttpStatusCode.NotFound) { call, _ -> call.respond( diff --git a/src/main/resources/logback.xml b/src/main/resources/logback.xml index 80b255b..438098b 100644 --- a/src/main/resources/logback.xml +++ b/src/main/resources/logback.xml @@ -7,12 +7,11 @@ + - -