Skip to content

Commit

Permalink
Merge branch 'main' of github.com:navikt/send-in-send-out
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanskodje committed Oct 10, 2024
2 parents 24efdc1 + 8f2001a commit 27d6992
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
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")

0 comments on commit 27d6992

Please sign in to comment.