Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ny instans av timeout i cpa-sync ved kall til cpa-repo timestamps endepunkt #1

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions cpa-sync/src/main/kotlin/no/nav/emottak/cpa/HttpClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.nimbusds.jwt.SignedJWT
import io.ktor.client.HttpClient
import io.ktor.client.HttpClientConfig
import io.ktor.client.engine.cio.CIO
import io.ktor.client.plugins.HttpTimeout
import io.ktor.client.plugins.auth.Auth
import io.ktor.client.plugins.auth.providers.BearerTokens
import io.ktor.client.plugins.auth.providers.bearer
Expand Down Expand Up @@ -78,6 +79,9 @@ suspend fun getCpaRepoToken(): BearerTokens {

fun getCpaRepoAuthenticatedClient(): HttpClient {
return HttpClient(CIO) {
install(HttpTimeout) {
this.requestTimeoutMillis = 60000
}
install(ContentNegotiation) {
json()
}
Expand Down
13 changes: 11 additions & 2 deletions cpa-sync/src/main/kotlin/no/nav/emottak/cpa/Routes.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package no.nav.emottak.cpa

import io.ktor.client.network.sockets.ConnectTimeoutException
import io.ktor.client.plugins.HttpRequestTimeoutException
import io.ktor.client.request.get
import io.ktor.client.statement.bodyAsText
import io.ktor.http.HttpStatusCode
Expand Down Expand Up @@ -27,8 +29,15 @@ fun Route.cpaSync(): Route = get("/cpa-sync") {
}
result.onSuccess {
log.info("CPA sync completed in $duration")
TIMEOUT_EXCEPTION_COUNTER = 0
call.respond(HttpStatusCode.OK, "CPA sync complete")
}.onFailure {
when (it) {
// flere feilhåndteringer pga. vi ikke er sikre på hvilken timeout er det.
is HttpRequestTimeoutException, is ConnectTimeoutException -> log.error("Timeout exception", it)
.also { TIMEOUT_EXCEPTION_COUNTER++ }
else -> log.error(it.message, it)
}
call.respond(HttpStatusCode.InternalServerError, "Something went wrong")
}
}
Expand All @@ -43,10 +52,10 @@ fun Route.testAzureAuthToCpaRepo(): Route = get("/testCpaRepoConnection") {
)
}

var BUG_ENCOUNTERED_CPA_REPO_TIMEOUT = false
var TIMEOUT_EXCEPTION_COUNTER = 0
fun Routing.registerHealthEndpoints() {
get("/internal/health/liveness") {
if (BUG_ENCOUNTERED_CPA_REPO_TIMEOUT) { // TODO : årsak ukjent, cpa-repo/timestamps endepunkt timer ut etter en stund
if (TIMEOUT_EXCEPTION_COUNTER > 5) { // TODO : årsak ukjent, cpa-repo/timestamps endepunkt timer ut etter en stund
call.respond(HttpStatusCode.ServiceUnavailable, "Restart me X_X")
} else {
call.respondText("I'm alive! :)")
Expand Down
2 changes: 1 addition & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -147,5 +147,5 @@ dependencyResolutionManagement {
}
}

rootProject.name = "ebxml-processor"
rootProject.name = "send-in-send-out"
include("felles", "smtp-transport", "ebms-send-in", "cpa-sync")
Loading