From 38a48577740d8384d3feb0785c37492bf21b1192 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98yvind=20Haarberg?= Date: Fri, 13 Dec 2024 15:45:16 +0100 Subject: [PATCH] =?UTF-8?q?Setter=20opp=20jobben=20for=20=C3=A5=20resende?= =?UTF-8?q?=20avbrutte=20meldinger?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/kotlin/Application.kt | 1 + .../behandling/jobs/ResendManglendeAvbrytJob.kt | 10 +++++----- .../src/main/kotlin/config/ApplicationContext.kt | 15 +++++++++++++++ 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/apps/etterlatte-behandling/src/main/kotlin/Application.kt b/apps/etterlatte-behandling/src/main/kotlin/Application.kt index 032a6d08e3e..f8b6e42cd0b 100644 --- a/apps/etterlatte-behandling/src/main/kotlin/Application.kt +++ b/apps/etterlatte-behandling/src/main/kotlin/Application.kt @@ -94,6 +94,7 @@ private fun timerJobs(context: ApplicationContext): List = context.doedsmeldingerJob, context.doedsmeldingerReminderJob, context.saksbehandlerJob, + context.sendAvbruttMeldingJob, ) @Deprecated("Denne blir brukt i veldig mange testar. Bør rydde opp, men tar det etter denne endringa er inne") diff --git a/apps/etterlatte-behandling/src/main/kotlin/behandling/jobs/ResendManglendeAvbrytJob.kt b/apps/etterlatte-behandling/src/main/kotlin/behandling/jobs/ResendManglendeAvbrytJob.kt index 577abd8f5c2..6d9e3497386 100644 --- a/apps/etterlatte-behandling/src/main/kotlin/behandling/jobs/ResendManglendeAvbrytJob.kt +++ b/apps/etterlatte-behandling/src/main/kotlin/behandling/jobs/ResendManglendeAvbrytJob.kt @@ -15,7 +15,6 @@ import no.nav.etterlatte.libs.common.behandling.BehandlingHendelseType import no.nav.etterlatte.libs.common.feilhaandtering.InternfeilException import no.nav.etterlatte.libs.common.sak.SakId import no.nav.etterlatte.libs.common.tidspunkt.toTidspunkt -import no.nav.etterlatte.libs.jobs.LeaderElection import no.nav.etterlatte.libs.ktor.token.HardkodaSystembruker import org.slf4j.LoggerFactory import java.time.Duration @@ -24,7 +23,7 @@ import java.util.Timer import java.util.UUID class ResendManglendeAvbrytJob( - private val leaderElection: LeaderElection, + private val erLeader: () -> Boolean, private val kafkaProducer: BehandlingHendelserKafkaProducer, private val sendManglendeMeldingerDao: SendManglendeMeldingerDao, private val behandlingDao: BehandlingDao, @@ -49,7 +48,7 @@ class ResendManglendeAvbrytJob( ), ) { SendManglendeAvbrytMelding( - leaderElection, + erLeader, sendManglendeMeldingerDao, kafkaProducer, behandlingDao, @@ -60,7 +59,7 @@ class ResendManglendeAvbrytJob( } class SendManglendeAvbrytMelding( - private val leaderElection: LeaderElection, + private val erLeader: () -> Boolean, private val sendManglendeMeldingerDao: SendManglendeMeldingerDao, private val kafkaProducer: BehandlingHendelserKafkaProducer, private val behandlingDao: BehandlingDao, @@ -70,8 +69,9 @@ class ResendManglendeAvbrytJob( private val logger = LoggerFactory.getLogger(SendManglendeAvbrytMelding::class.java) fun send() { - if (!leaderElection.isLeader()) { + if (!erLeader()) { logger.info("Er ikke leader, kjører ikke ${SendManglendeAvbrytMelding::class.java.simpleName}-jobb") + return } try { val behandlinger = inTransaction { sendManglendeMeldingerDao.hentManglendeAvslagBehandling() } diff --git a/apps/etterlatte-behandling/src/main/kotlin/config/ApplicationContext.kt b/apps/etterlatte-behandling/src/main/kotlin/config/ApplicationContext.kt index d5262fb4b0f..1c0311c35d5 100644 --- a/apps/etterlatte-behandling/src/main/kotlin/config/ApplicationContext.kt +++ b/apps/etterlatte-behandling/src/main/kotlin/config/ApplicationContext.kt @@ -21,6 +21,7 @@ import no.nav.etterlatte.behandling.BehandlingsHendelserKafkaProducerImpl import no.nav.etterlatte.behandling.BrukerServiceImpl import no.nav.etterlatte.behandling.GrunnlagServiceImpl import no.nav.etterlatte.behandling.GyldighetsproevingServiceImpl +import no.nav.etterlatte.behandling.SendManglendeMeldingerDao import no.nav.etterlatte.behandling.aktivitetsplikt.AktivitetspliktBrevDao import no.nav.etterlatte.behandling.aktivitetsplikt.AktivitetspliktDao import no.nav.etterlatte.behandling.aktivitetsplikt.AktivitetspliktKopierService @@ -39,6 +40,7 @@ import no.nav.etterlatte.behandling.hendelse.HendelseDao import no.nav.etterlatte.behandling.job.SaksbehandlerJobService import no.nav.etterlatte.behandling.jobs.DoedsmeldingJob import no.nav.etterlatte.behandling.jobs.DoedsmeldingReminderJob +import no.nav.etterlatte.behandling.jobs.ResendManglendeAvbrytJob import no.nav.etterlatte.behandling.jobs.SaksbehandlerJob import no.nav.etterlatte.behandling.klage.KlageBrevService import no.nav.etterlatte.behandling.klage.KlageDaoImpl @@ -322,6 +324,8 @@ internal class ApplicationContext( val vilkaarsvurderingRepositoryWrapper: VilkaarsvurderingRepositoryWrapper = VilkaarsvurderingRepositoryWrapperDatabase(vilkaarsvurderingDao) + val sendManglendeMeldingerDao: SendManglendeMeldingerDao = SendManglendeMeldingerDao(autoClosingDatabase) + // Klient val skjermingKlient = SkjermingKlient(skjermingHttpKlient, env.requireEnvValue(SKJERMING_URL)) val leaderElectionKlient = LeaderElection(env[ELECTOR_PATH], leaderElectionHttpClient) @@ -658,6 +662,17 @@ internal class ApplicationContext( ) } + val sendAvbruttMeldingJob: ResendManglendeAvbrytJob by lazy { + ResendManglendeAvbrytJob( + erLeader = { leaderElectionKlient.isLeader() }, + kafkaProducer = behandlingsHendelser, + sendManglendeMeldingerDao = sendManglendeMeldingerDao, + behandlingDao = behandlingDao, + grunnlagKlient = grunnlagKlientImpl, + hendelseDao = hendelseDao, + ) + } + fun close() { (dataSource as HikariDataSource).close() }