Skip to content

Commit

Permalink
Cache config dokumentmaler skille på dev og prod (#111)
Browse files Browse the repository at this point in the history
* Cache config dokumentmaler skille på dev og prod

* Cache config dokumentmaler skille på dev og prod
  • Loading branch information
ugur93 authored Oct 10, 2023
1 parent 2ced7d5 commit 83f2945
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 18 deletions.
1 change: 0 additions & 1 deletion .nais/feature.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ env:
OPPDATER_STATUS_DOKUMENTER_CRON: "1 * * * * ?"
REBESTILL_DOKUMENTER_UNDER_PRODUKSJON_SCHEDULE: "0 */10 * * * *"
REBESTILL_DOKUMENTER_BESTILLING_FEILET_SCHEDULE: "0 */10 * * * *"
OPPDATER_DIST_STATUS_ENABLED: true
KAFKA_MAX_RETRY: 5
GCP_BUCKET_DOCUMENT_KMS_KEY_PATH: projects/bidrag-dev-45a9/locations/europe-north1/keyRings/bidrag-dokument-forsendelse-feature/cryptoKeys/bucket-dokument-encryption
GCP_DOCUMENT_CLIENTSIDE_KMS_KEY_PATH: gcp-kms://projects/bidrag-dev-45a9/locations/europe-north1/keyRings/bidrag-dokument-forsendelse-feature/cryptoKeys/clientside_document_encryption
Expand Down
1 change: 0 additions & 1 deletion .nais/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ env:
OPPDATER_STATUS_DOKUMENTER_CRON: "1 * * * * ?"
REBESTILL_DOKUMENTER_UNDER_PRODUKSJON_SCHEDULE: "0 */10 * * * *"
REBESTILL_DOKUMENTER_BESTILLING_FEILET_SCHEDULE: "0 */10 * * * *"
OPPDATER_DIST_STATUS_ENABLED: true
KAFKA_MAX_RETRY: 5
GCP_BUCKET_DOCUMENT_KMS_KEY_PATH: projects/bidrag-dev-45a9/locations/europe-north1/keyRings/bidrag-dokument-forsendelse-feature/cryptoKeys/bucket-dokument-encryption
GCP_DOCUMENT_CLIENTSIDE_KMS_KEY_PATH: gcp-kms://projects/bidrag-dev-45a9/locations/europe-north1/keyRings/bidrag-dokument-forsendelse-feature/cryptoKeys/clientside_document_encryption
Expand Down
1 change: 0 additions & 1 deletion .nais/prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ env:
OPPDATER_STATUS_DOKUMENTER_CRON: "* */10 * * * ?"
REBESTILL_DOKUMENTER_UNDER_PRODUKSJON_SCHEDULE: "0 */10 * * * *"
REBESTILL_DOKUMENTER_BESTILLING_FEILET_SCHEDULE: "0 * * * * *"
OPPDATER_DIST_STATUS_ENABLED: true
GCP_DOCUMENT_CLIENTSIDE_KMS_KEY_PATH: gcp-kms://projects/bidrag-prod-8f72/locations/europe-north1/keyRings/bidrag-dokument-forsendelse/cryptoKeys/clientside_document_encryption

JAVA_OPTS: -Xmx1028m -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/tmp -XX:MaxRAMPercentage=80.0
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package no.nav.bidrag.dokument.forsendelse.config

import com.github.benmanes.caffeine.cache.Caffeine
import mu.KotlinLogging
import no.nav.bidrag.commons.cache.EnableUserCache
import no.nav.bidrag.commons.cache.InvaliderCacheFørStartenAvArbeidsdag
import org.springframework.beans.factory.annotation.Value
import org.springframework.cache.CacheManager
import org.springframework.cache.annotation.EnableCaching
import org.springframework.cache.caffeine.CaffeineCacheManager
Expand All @@ -11,6 +13,8 @@ import org.springframework.context.annotation.Configuration
import org.springframework.context.annotation.Profile
import java.util.concurrent.TimeUnit

private val log = KotlinLogging.logger {}

@Configuration
@EnableCaching
@Profile(value = ["!test"]) // Ignore cache on tests
Expand All @@ -31,15 +35,20 @@ class CacheConfig {
}

@Bean
fun cacheManager(): CacheManager {
fun cacheManager(@Value("\${NAIS_CLUSTER_NAME:dev-gcp}") clusterName: String): CacheManager {
val isProd = clusterName.startsWith("prod")
val caffeineCacheManager = CaffeineCacheManager()
caffeineCacheManager.registerCustomCache(
PERSON_SPRAAK_CACHE,
Caffeine.newBuilder().expireAfter(InvaliderCacheFørStartenAvArbeidsdag()).build()
)
val dokumentMalerCache = if (isProd) Caffeine.newBuilder().expireAfterWrite(1, TimeUnit.HOURS)
else Caffeine.newBuilder().expireAfterWrite(2, TimeUnit.MINUTES)

log.info { "Bruker cache $dokumentMalerCache for dokumentmaler. Kjører i cluster $clusterName" }
caffeineCacheManager.registerCustomCache(PERSON_CACHE, Caffeine.newBuilder().expireAfter(InvaliderCacheFørStartenAvArbeidsdag()).build())
caffeineCacheManager.registerCustomCache(DOKUMENTMALER_CACHE, Caffeine.newBuilder().expireAfterWrite(24, TimeUnit.HOURS).build())
caffeineCacheManager.registerCustomCache(DOKUMENTMALDETALJER_CACHE, Caffeine.newBuilder().expireAfterWrite(24, TimeUnit.HOURS).build())
caffeineCacheManager.registerCustomCache(DOKUMENTMALER_CACHE, dokumentMalerCache.build())
caffeineCacheManager.registerCustomCache(DOKUMENTMALDETALJER_CACHE, dokumentMalerCache.build())
caffeineCacheManager.registerCustomCache(TILGANG_TEMA_CACHE, Caffeine.newBuilder().expireAfterWrite(1, TimeUnit.HOURS).build())
caffeineCacheManager.registerCustomCache(TILGANG_PERSON_CACHE, Caffeine.newBuilder().expireAfterWrite(1, TimeUnit.HOURS).build())
caffeineCacheManager.registerCustomCache(TILGANG_SAK_CACHE, Caffeine.newBuilder().expireAfterWrite(1, TimeUnit.HOURS).build())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ class ForsendelseSkedulering(
private val forsendelseTjeneste: ForsendelseTjeneste,
private val distribusjonService: DistribusjonService,
private val forsendelseHendelseBestilling: ForsendelseHendelseBestillingService,
@Value("\${LAGRE_DIST_INFO_PAGE_SIZE:10}") private val distInfoPageSize: Int,
@Value("\${OPPDATER_DIST_STATUS_ENABLED:true}") private val forsendelseDistStatusEnabled: Boolean
@Value("\${LAGRE_DIST_INFO_PAGE_SIZE:10}") private val distInfoPageSize: Int
) {

@Scheduled(cron = "\${LAGRE_DIST_INFO_CRON}")
Expand Down Expand Up @@ -58,13 +57,7 @@ class ForsendelseSkedulering(
?.let { distInfo ->
LOGGER.info {
"Forsendelse ${forsendelse.forsendelseId} har status ${ForsendelseStatus.FERDIGSTILT} men journalpost ${forsendelse.journalpostIdFagarkiv} er distribuert med status ${distInfo.journalstatus} og kanal ${distInfo.kanal}. " +
"Oppdaterer forsendelsestatus til ${ForsendelseStatus.DISTRIBUERT}"
}
if (!forsendelseDistStatusEnabled) {
LOGGER.info {
"Oppdatering av Forsendelse status er ikke skrudd på. Oppdaterer ikke forsendelse"
}
return
"Oppdaterer forsendelsestatus til ${ForsendelseStatus.DISTRIBUERT}"
}
val kanal = DistribusjonKanal.valueOf(distInfo.kanal)
forsendelseTjeneste.lagre(
Expand Down Expand Up @@ -106,9 +99,9 @@ class ForsendelseSkedulering(
distribusjonService.hentDistribusjonInfo(forsendelse.journalpostIdFagarkiv)?.let { distInfo ->
LOGGER.info {
"Lagrer forsendelse distribusjon info for forsendelse ${forsendelse.forsendelseId} " +
"med JOARK journalpostId ${forsendelse.journalpostIdFagarkiv}, " +
"${forsendelse.dokumenter.size} dokumenter, " +
"kanal ${distInfo.kanal} og status ${distInfo.journalstatus}"
"med JOARK journalpostId ${forsendelse.journalpostIdFagarkiv}, " +
"${forsendelse.dokumenter.size} dokumenter, " +
"kanal ${distInfo.kanal} og status ${distInfo.journalstatus}"
}
forsendelseTjeneste.lagre(
forsendelse.copy(
Expand Down

0 comments on commit 83f2945

Please sign in to comment.