Skip to content

Commit

Permalink
Lengre timeout på kall fra behandling til brev-api for forhåndsvisning.
Browse files Browse the repository at this point in the history
  • Loading branch information
tvsignal committed Feb 27, 2025
1 parent 683b5a7 commit 2047b40
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.github.michaelbull.result.mapBoth
import com.github.michaelbull.result.mapError
import com.typesafe.config.Config
import io.ktor.client.HttpClient
import io.ktor.client.plugins.HttpTimeout
import no.nav.etterlatte.behandling.objectMapper
import no.nav.etterlatte.brev.BrevParametre
import no.nav.etterlatte.brev.BrevPayload
Expand All @@ -27,6 +28,7 @@ import no.nav.etterlatte.libs.ktor.ktor.ktorobo.DownstreamResourceClient
import no.nav.etterlatte.libs.ktor.ktor.ktorobo.Resource
import no.nav.etterlatte.libs.ktor.route.SAKID_CALL_PARAMETER
import no.nav.etterlatte.libs.ktor.token.BrukerTokenInfo
import java.time.Duration
import java.util.UUID

interface BrevApiKlient {
Expand Down Expand Up @@ -372,6 +374,10 @@ class BrevApiKlientObo(
?: throw InternfeilException("Feil ved generering av pdf vedtaksbrev")
},
brukerTokenInfo = brukerTokenInfo,
timeoutConfig = {
socketTimeoutMillis = Duration.ofSeconds(30).toMillis()
requestTimeoutMillis = Duration.ofSeconds(30).toMillis()
},
)

override suspend fun tilbakestillVedtaksbrev(
Expand Down Expand Up @@ -416,11 +422,13 @@ class BrevApiKlientObo(
url: String,
onSuccess: (Resource) -> T,
brukerTokenInfo: BrukerTokenInfo,
timeoutConfig: (HttpTimeout.HttpTimeoutCapabilityConfiguration.() -> Unit)? = null,
): T =
downstreamResourceClient
.get(
resource = Resource(clientId = clientId, url = url),
brukerTokenInfo = brukerTokenInfo,
timeoutConfig = timeoutConfig,
).mapBoth(
success = onSuccess,
failure = { throwableErrorMessage -> throw throwableErrorMessage },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import com.github.michaelbull.result.Ok
import com.github.michaelbull.result.andThen
import io.ktor.client.HttpClient
import io.ktor.client.call.body
import io.ktor.client.plugins.HttpTimeout
import io.ktor.client.plugins.timeout
import io.ktor.client.request.accept
import io.ktor.client.request.bearerAuth
import io.ktor.client.request.delete
Expand All @@ -23,6 +25,7 @@ import io.ktor.http.isSuccess
import no.nav.etterlatte.libs.ktor.navConsumerId
import no.nav.etterlatte.libs.ktor.token.BrukerTokenInfo
import org.slf4j.LoggerFactory
import java.time.Duration

class DownstreamResourceClient(
private val azureAdClient: AzureAdClient,
Expand All @@ -33,9 +36,16 @@ class DownstreamResourceClient(
suspend fun get(
resource: Resource,
brukerTokenInfo: BrukerTokenInfo,
timeoutConfig: (HttpTimeout.HttpTimeoutCapabilityConfiguration.() -> Unit)? = null,
) = medToken(resource, brukerTokenInfo) { token ->
httpClient.get(resource.url) {
bearerAuth(token.accessToken)
timeoutConfig?.let { config ->
timeout {
apply(config)
}
}

resource.additionalHeaders?.forEach { headers.append(it.key, it.value) }
}
}
Expand All @@ -46,6 +56,10 @@ class DownstreamResourceClient(
) = httpClient.get(url) {
accept(ContentType.Application.Json)
navConsumerId(konsument)
timeout {
socketTimeoutMillis = Duration.ofSeconds(30).toMillis()
requestTimeoutMillis = Duration.ofSeconds(30).toMillis()
}
}

suspend fun post(
Expand Down

0 comments on commit 2047b40

Please sign in to comment.