Skip to content

Commit

Permalink
chore: drop restart application on error (#263)
Browse files Browse the repository at this point in the history
  • Loading branch information
MikAoJk authored Oct 15, 2024
1 parent 182471b commit c535421
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 13 deletions.
8 changes: 3 additions & 5 deletions src/main/kotlin/no/nav/pdfgen/Application.kt
Original file line number Diff line number Diff line change
@@ -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.*
Expand Down Expand Up @@ -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)
}
Expand Down
9 changes: 7 additions & 2 deletions src/main/kotlin/no/nav/pdfgen/plugins/LifecycleHooks.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
5 changes: 1 addition & 4 deletions src/main/kotlin/no/nav/pdfgen/plugins/StatusPages.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,11 @@ import no.nav.pdfgen.logger

fun Application.configureStatusPages(
templates: Map<Pair<String, String>, Template>,
applicationState: ApplicationState
) {
install(StatusPages) {
exception<Throwable> { 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(
Expand Down
3 changes: 1 addition & 2 deletions src/main/resources/logback.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@
</appender>

<logger name="pdfgen" level="INFO"/>
<logger name="org.apache.pdfbox" level="ERROR" />

<root level="INFO">
<appender-ref ref="stdout_json" />
</root>

<logger name="org.apache.pdfbox" level="ERROR" />

</configuration>

0 comments on commit c535421

Please sign in to comment.