Skip to content

Commit

Permalink
IS-2643: Turn off journalforing-retry in dev (#559)
Browse files Browse the repository at this point in the history
  • Loading branch information
geir-waagboe authored Dec 19, 2024
1 parent 9d2e052 commit e0d469b
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 74 deletions.
2 changes: 2 additions & 0 deletions .nais/naiserator-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ spec:
env:
- name: KTOR_ENV
value: production
- name: JOURNALFORING_RETRY_ENABLED
value: "false"
- name: DOKARKIV_CLIENT_ID
value: "dev-fss.teamdokumenthandtering.dokarkiv-q1"
- name: DOKARKIV_URL
Expand Down
2 changes: 2 additions & 0 deletions .nais/naiserator-prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ spec:
env:
- name: KTOR_ENV
value: "production"
- name: JOURNALFORING_RETRY_ENABLED
value: "true"
- name: DOKARKIV_CLIENT_ID
value: "prod-fss.teamdokumenthandtering.dokarkiv"
- name: DOKARKIV_URL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ data class Environment(
val altinnPassword: String = getEnvVar("ALTINN_PASSWORD"),
val altinnSendingEnabled: Boolean = getEnvVar("ALTINN_SENDING_ENABLED").toBoolean(),
val outdatedDialogmoteCutoff: LocalDate = LocalDate.parse(getEnvVar("OUTDATED_DIALOGMOTE_CUTOFF")),
val isJournalforingRetryEnabled: Boolean = getEnvVar("JOURNALFORING_RETRY_ENABLED").toBoolean(),
) {
fun jdbcUrl(): String {
return "jdbc:postgresql://$isdialogmoteDbHost:$isdialogmoteDbPort/$isdialogmoteDbName"
Expand Down
1 change: 1 addition & 0 deletions src/main/kotlin/no/nav/syfo/cronjob/CronjobModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ fun Application.cronjobModule(
dokarkivClient = dokarkivClient,
pdlClient = pdlClient,
eregClient = eregClient,
isJournalforingRetryEnabled = environment.isJournalforingRetryEnabled,
)

val kafkaDialogmoteStatusEndringProducerProperties = kafkaDialogmoteStatusEndringProducerConfig(environment.kafka)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package no.nav.syfo.cronjob.journalforing

import net.logstash.logback.argument.StructuredArguments
import no.nav.syfo.client.dokarkiv.DokarkivClient
import no.nav.syfo.client.dokarkiv.domain.JournalpostRequest
import no.nav.syfo.client.ereg.EregClient
import no.nav.syfo.client.pdl.PdlClient
import no.nav.syfo.cronjob.COUNT_CRONJOB_JOURNALFORING_VARSEL_FAIL
Expand All @@ -19,6 +20,7 @@ class DialogmoteVarselJournalforingCronjob(
private val dokarkivClient: DokarkivClient,
private val pdlClient: PdlClient,
private val eregClient: EregClient,
private val isJournalforingRetryEnabled: Boolean,
) : DialogmoteCronjob {

override val initialDelayMinutes: Long = 2
Expand Down Expand Up @@ -53,21 +55,17 @@ class DialogmoteVarselJournalforingCronjob(
try {
val navn = pdlClient.navn(personIdent)
val pdf = pdfService.getPdf(arbeidstakerVarsel.pdfId)
val journalpostId = dokarkivClient.journalfor(
journalpostRequest = arbeidstakerVarsel.toJournalpostRequest(
personIdent = personIdent,
navn = navn,
pdf = pdf,
),
)?.journalpostId

journalpostId?.let { it ->
dialogmotedeltakerVarselJournalpostService.updateArbeidstakerVarselJournalpostId(
arbeidstakerVarsel,
it,
)
journalforingResult.updated++
} ?: throw RuntimeException("Failed to Journalfor ArbeidstakerVarsel: response missing JournalpostId")
val journalpostRequest = arbeidstakerVarsel.toJournalpostRequest(
personIdent = personIdent,
navn = navn,
pdf = pdf,
)
val journalpostId = journalfor(journalpostRequest)
dialogmotedeltakerVarselJournalpostService.updateArbeidstakerVarselJournalpostId(
arbeidstakerVarsel,
journalpostId,
)
journalforingResult.updated++
} catch (e: Exception) {
log.error("Exception caught while attempting Journalforing of ArbeidstakerVarsel, will try again later", e)
journalforingResult.failed++
Expand All @@ -84,22 +82,18 @@ class DialogmoteVarselJournalforingCronjob(
try {
val virksomhetsnavn = eregClient.organisasjonVirksomhetsnavn(virksomhetsnummer)
val pdf = pdfService.getPdf(arbeidsgiverVarsel.pdfId)
val journalpostId = dokarkivClient.journalfor(
journalpostRequest = arbeidsgiverVarsel.toJournalpostRequest(
brukerPersonIdent = personIdent,
virksomhetsnummer = virksomhetsnummer,
virksomhetsnavn = virksomhetsnavn?.virksomhetsnavn ?: "",
pdf = pdf,
),
)?.journalpostId

journalpostId?.let { it ->
dialogmotedeltakerVarselJournalpostService.updateArbeidsgiverVarselJournalpostId(
arbeidsgiverVarsel,
it,
)
journalforingResult.updated++
} ?: throw RuntimeException("Failed to Journalfor ArbeidsgiverVarsel: response missing JournalpostId")
val journalpostRequest = arbeidsgiverVarsel.toJournalpostRequest(
brukerPersonIdent = personIdent,
virksomhetsnummer = virksomhetsnummer,
virksomhetsnavn = virksomhetsnavn?.virksomhetsnavn ?: "",
pdf = pdf,
)
val journalpostId = journalfor(journalpostRequest)
dialogmotedeltakerVarselJournalpostService.updateArbeidsgiverVarselJournalpostId(
arbeidsgiverVarsel,
journalpostId,
)
journalforingResult.updated++
} catch (e: Exception) {
log.error("Exception caught while attempting Journalforing of ArbeidsgiverVarsel", e)
journalforingResult.failed++
Expand All @@ -115,22 +109,18 @@ class DialogmoteVarselJournalforingCronjob(
behandlerVarselForJournalforingList.forEach { (personIdent, behandler, behandlerVarsel) ->
try {
val pdf = pdfService.getPdf(behandlerVarsel.pdfId)
val journalpostId = dokarkivClient.journalfor(
journalpostRequest = behandlerVarsel.toJournalpostRequest(
brukerPersonIdent = personIdent,
behandlerPersonIdent = behandler.personIdent,
behandlerNavn = behandler.behandlerNavn,
pdf = pdf,
),
)?.journalpostId

journalpostId?.let { it ->
dialogmotedeltakerVarselJournalpostService.updateBehandlerVarselJournalpostId(
behandlerVarsel,
it,
)
journalforingResult.updated++
} ?: throw RuntimeException("Failed to Journalfor BehandlerVarsel: response missing JournalpostId")
val journalpostRequest = behandlerVarsel.toJournalpostRequest(
brukerPersonIdent = personIdent,
behandlerPersonIdent = behandler.personIdent,
behandlerNavn = behandler.behandlerNavn,
pdf = pdf,
)
val journalpostId = journalfor(journalpostRequest)
dialogmotedeltakerVarselJournalpostService.updateBehandlerVarselJournalpostId(
behandlerVarsel,
journalpostId,
)
journalforingResult.updated++
} catch (e: Exception) {
log.error("Exception caught while attempting Journalforing of BehandlerVarsel", e)
journalforingResult.failed++
Expand All @@ -154,15 +144,12 @@ class DialogmoteVarselJournalforingCronjob(
moteTidspunkt = moteTidspunkt,
)
log.info("Journalfør referat to arbeidstaker with uuid ${referat.uuid} and eksternReferanseId: ${journalpostRequest.eksternReferanseId}")
val journalpostId = dokarkivClient.journalfor(journalpostRequest)?.journalpostId

journalpostId?.let { it ->
referatJournalpostService.updateJournalpostIdArbeidstakerForReferat(
referat,
it,
)
journalforingResult.updated++
} ?: throw RuntimeException("Failed to Journalfor Referat: response missing JournalpostId")
val journalpostId = journalfor(journalpostRequest)
referatJournalpostService.updateJournalpostIdArbeidstakerForReferat(
referat,
journalpostId,
)
journalforingResult.updated++
} catch (e: Exception) {
log.error("Exception caught while attempting Journalforing of Referat", e)
journalforingResult.failed++
Expand All @@ -187,15 +174,12 @@ class DialogmoteVarselJournalforingCronjob(
moteTidspunkt = moteTidspunkt,
)
log.info("Journalfør referat to arbeidsgiver with uuid ${referat.uuid} and eksternReferanseId: ${journalpostRequest.eksternReferanseId}")
val journalpostId = dokarkivClient.journalfor(journalpostRequest)?.journalpostId

journalpostId?.let { it ->
referatJournalpostService.updateJournalpostIdArbeidsgiverForReferat(
referat,
it,
)
journalforingResult.updated++
} ?: throw RuntimeException("Failed to Journalfor Referat: response missing JournalpostId")
val journalpostId = journalfor(journalpostRequest)
referatJournalpostService.updateJournalpostIdArbeidsgiverForReferat(
referat,
journalpostId,
)
journalforingResult.updated++
} catch (e: Exception) {
log.error("Exception caught while attempting Journalforing of Referat", e)
journalforingResult.failed++
Expand All @@ -219,23 +203,38 @@ class DialogmoteVarselJournalforingCronjob(
moteTidspunkt = moteTidspunkt,
)
log.info("Journalfør referat to behandler with uuid ${referat.uuid} and eksternReferanseId: ${journalpostRequest.eksternReferanseId}")
val journalpostId = dokarkivClient.journalfor(journalpostRequest)?.journalpostId

journalpostId?.let { it ->
referatJournalpostService.updateJournalpostIdBehandlerForReferat(
referat,
it,
)
journalforingResult.updated++
} ?: throw RuntimeException("Failed to Journalfor Referat: response missing JournalpostId")
val journalpostId = journalfor(journalpostRequest)
referatJournalpostService.updateJournalpostIdBehandlerForReferat(
referat,
journalpostId,
)
journalforingResult.updated++
} catch (e: Exception) {
log.error("Exception caught while attempting Journalforing of Referat", e)
journalforingResult.failed++
}
}
}

private suspend fun journalfor(journalpostRequest: JournalpostRequest): Int {
val journalpostResponse = dokarkivClient.journalfor(journalpostRequest)
return if (journalpostResponse?.journalpostId == null) {
if (isJournalforingRetryEnabled) {
throw RuntimeException("Failed journalforing: response missing journalpostId")
} else {
log.error("Journalforing failed, skipping retry (should only happen in dev-gcp)")
// Defaulting'en til DEFAULT_FAILED_JP_ID skal bare forekomme i dev-gcp:
// Har dette fordi vi ellers spammer ned dokarkiv med forsøk på å journalføre
// på personer som mangler aktør-id.
DEFAULT_FAILED_JP_ID
}
} else {
journalpostResponse.journalpostId
}
}

companion object {
private const val DEFAULT_FAILED_JP_ID = 0
private val log = LoggerFactory.getLogger(DialogmoteVarselJournalforingCronjob::class.java)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ class DialogmoteVarselJournalforingCronjobSpek : Spek({
dokarkivClient = dokarkivClient,
pdlClient = pdlClient,
eregClient = eregClient,
isJournalforingRetryEnabled = externalMockEnvironment.environment.isJournalforingRetryEnabled,
)

beforeEachTest {
Expand Down
1 change: 1 addition & 0 deletions src/test/kotlin/no/nav/syfo/testhelper/TestEnvironment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ fun testEnvironment(
altinnPassword = "password",
altinnSendingEnabled = true,
outdatedDialogmoteCutoff = LocalDate.parse("2022-07-01"),
isJournalforingRetryEnabled = true,
)

fun testAppState() = ApplicationState(
Expand Down

0 comments on commit e0d469b

Please sign in to comment.