-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature to create new behandling for old grunnlag for analysis.
- Loading branch information
1 parent
f5af3c1
commit dca6468
Showing
26 changed files
with
1,358 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
...ning/omsorgsopptjening/bestem/pensjonsopptjening/kontrollbehandling/Kontrollbehandling.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package no.nav.pensjon.opptjening.omsorgsopptjening.bestem.pensjonsopptjening.kontrollbehandling | ||
|
||
import java.time.Instant | ||
import java.util.UUID | ||
|
||
data class Kontrollbehandling( | ||
val kontrollId: UUID, | ||
val opprettet: Instant, | ||
val kontrollmeldingId: UUID, | ||
val statushistorikk: List<KontrollbehandlingStatus> = listOf(KontrollbehandlingStatus.Klar()), | ||
val referanse: String, | ||
val omsorgsÅr: Int, | ||
val kafkameldingid: UUID, | ||
) { | ||
val status: KontrollbehandlingStatus get() = statushistorikk.last() | ||
|
||
fun ferdig(): Kontrollbehandling { | ||
return copy(statushistorikk = statushistorikk + status.ferdig()) | ||
} | ||
|
||
fun retry(melding: String): Kontrollbehandling { | ||
return copy(statushistorikk = statushistorikk + status.retry(melding)) | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
...ening/bestem/pensjonsopptjening/kontrollbehandling/KontrollbehandlingProcessingService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package no.nav.pensjon.opptjening.omsorgsopptjening.bestem.pensjonsopptjening.kontrollbehandling | ||
|
||
import no.nav.pensjon.opptjening.omsorgsopptjening.bestem.pensjonsopptjening.omsorgsopptjening.model.FullførteBehandlinger | ||
|
||
interface KontrollbehandlingProcessingService { | ||
fun process(): List<FullførteBehandlinger>? | ||
} |
52 changes: 52 additions & 0 deletions
52
...g/bestem/pensjonsopptjening/kontrollbehandling/KontrollbehandlingProcessingServiceImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package no.nav.pensjon.opptjening.omsorgsopptjening.bestem.pensjonsopptjening.kontrollbehandling | ||
|
||
import no.nav.pensjon.opptjening.omsorgsopptjening.bestem.pensjonsopptjening.omsorgsopptjening.model.FullførteBehandlinger | ||
import no.nav.pensjon.opptjening.omsorgsopptjening.bestem.pensjonsopptjening.utils.Mdc | ||
import no.nav.pensjon.opptjening.omsorgsopptjening.bestem.pensjonsopptjening.utils.NewTransactionTemplate | ||
import no.nav.pensjon.opptjening.omsorgsopptjening.felles.CorrelationId | ||
import no.nav.pensjon.opptjening.omsorgsopptjening.felles.InnlesingId | ||
import org.slf4j.Logger | ||
import org.slf4j.LoggerFactory | ||
|
||
internal class KontrollbehandlingProcessingServiceImpl( | ||
private val transactionTemplate: NewTransactionTemplate, | ||
private val service: KontrollbehandlingService, | ||
) : KontrollbehandlingProcessingService { | ||
companion object { | ||
private val log: Logger = LoggerFactory.getLogger(this::class.java) | ||
private val secureLog: Logger = LoggerFactory.getLogger("secure") | ||
} | ||
|
||
override fun process(): List<FullførteBehandlinger>? { | ||
val meldinger = transactionTemplate.execute { service.hentOgLås(10) }!! | ||
try { | ||
return meldinger.rader.mapNotNull { melding -> | ||
Mdc.scopedMdc(CorrelationId(melding.kontrollId)) { | ||
Mdc.scopedMdc(InnlesingId(melding.kontrollId)) { | ||
try { | ||
log.info("Starter kontrollbehandling") | ||
transactionTemplate.execute { | ||
service.behandle(melding).also { log.info("Kontrollbehandling utført") } | ||
} | ||
} catch (ex: Throwable) { | ||
transactionTemplate.execute { | ||
log.warn("Exception ved kontrollbehandling: ${ex::class.qualifiedName}") | ||
secureLog.warn("Exception ved kontrollbehandling: ", ex) | ||
service.retry(melding, ex) | ||
} | ||
null | ||
} finally { | ||
log.info("Avslutter kontrollbehandling") | ||
} | ||
} | ||
} | ||
} | ||
} catch (ex: Throwable) { | ||
log.error("Exception ved henting kontrollbehandlinger ${ex::class.qualifiedName}") | ||
secureLog.error("Exception ved henting kontrollbehandlinger", ex) | ||
return null // throw ex | ||
} finally { | ||
transactionTemplate.execute { service.frigi(meldinger) } | ||
} | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
...jening/bestem/pensjonsopptjening/kontrollbehandling/KontrollbehandlingProcessingThread.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package no.nav.pensjon.opptjening.omsorgsopptjening.bestem.pensjonsopptjening.kontrollbehandling | ||
|
||
import io.getunleash.Unleash | ||
import no.nav.pensjon.opptjening.omsorgsopptjening.bestem.pensjonsopptjening.config.DatasourceReadinessCheck | ||
import no.nav.pensjon.opptjening.omsorgsopptjening.bestem.pensjonsopptjening.unleash.NavUnleashConfig | ||
import org.slf4j.LoggerFactory | ||
|
||
class KontrollbehandlingProcessingThread( | ||
private val service: KontrollbehandlingProcessingService, | ||
private val unleash: Unleash, | ||
private val datasourceReadinessCheck: DatasourceReadinessCheck, | ||
) : Runnable { | ||
|
||
init { | ||
val name = "prosesser-persongrunnlag-kontrollbehandling-thread" | ||
log.info("Starting new thread:$name to process kontrollbehandlinger") | ||
Thread(this, name).start() | ||
} | ||
|
||
|
||
companion object { | ||
private val log = LoggerFactory.getLogger(this::class.java)!! | ||
} | ||
|
||
|
||
override fun run() { | ||
while (true) { | ||
try { | ||
if (unleash.isEnabled(NavUnleashConfig.Feature.KONTROLL.toggleName) && datasourceReadinessCheck.isReady()) { | ||
service.process() ?: run { | ||
Thread.sleep(1000) | ||
null | ||
} | ||
} | ||
} catch (exception: Throwable) { | ||
log.warn("Exception caught while processing ${exception::class.qualifiedName}") | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.