Skip to content

Commit

Permalink
delay bør være lenge nok til at k8s har registrert det
Browse files Browse the repository at this point in the history
  • Loading branch information
davidsteinsland committed Nov 22, 2024
1 parent 4a18ee3 commit 59b7a2d
Showing 1 changed file with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import java.net.URI
import java.util.UUID
import java.util.concurrent.atomic.AtomicBoolean
import kotlin.String
import kotlin.time.Duration.Companion.seconds

data class NaisEndpoints(
val isaliveEndpoint: String,
Expand Down Expand Up @@ -99,7 +100,7 @@ fun naisApp(
port: Int = 8080,
aliveCheck: () -> Boolean = { true },
readyCheck: () -> Boolean = { true },
preStopHook: suspend () -> Unit = { delay(5000) },
preStopHook: suspend () -> Unit = ::defaultPreStopHook,
cioConfiguration: CIOApplicationEngine.Configuration.() -> Unit = { },
statusPagesConfig: StatusPagesConfig.() -> Unit = { defaultStatusPagesConfig() },
applicationModule: Application.() -> Unit
Expand Down Expand Up @@ -131,7 +132,7 @@ fun Application.standardApiModule(
callLogger: Logger,
naisEndpoints: NaisEndpoints,
callIdHeaderName: String,
preStopHook: suspend () -> Unit = { delay(5000) },
preStopHook: suspend () -> Unit = ::defaultPreStopHook,
aliveCheck: () -> Boolean = { true },
readyCheck: () -> Boolean = { true },
timersConfig: Timer.Builder.(ApplicationCall, Throwable?) -> Unit = { _, _ -> },
Expand Down Expand Up @@ -205,6 +206,16 @@ fun Application.standardApiModule(
}
}

internal suspend fun defaultPreStopHook() {
/* delayet bør være lenge nok til at:
a) k8s har prob'et appens isready-endepunkt og stoppet videreformidling av requests
b) alle pågående requests er ferdig
a) vil nok være den treigeste
*/
delay(30.seconds)
}

fun StatusPagesConfig.defaultStatusPagesConfig() {
exception<BadRequestException> { call, cause ->
call.response.header("Content-Type", ContentType.Application.ProblemJson.toString())
Expand Down

0 comments on commit 59b7a2d

Please sign in to comment.