Skip to content

Commit

Permalink
Setter opp jobben for å resende avbrutte meldinger
Browse files Browse the repository at this point in the history
  • Loading branch information
oyvindsh committed Dec 13, 2024
1 parent 4b5ea7e commit 38a4857
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
1 change: 1 addition & 0 deletions apps/etterlatte-behandling/src/main/kotlin/Application.kt
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ private fun timerJobs(context: ApplicationContext): List<TimerJob> =
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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -49,7 +48,7 @@ class ResendManglendeAvbrytJob(
),
) {
SendManglendeAvbrytMelding(
leaderElection,
erLeader,
sendManglendeMeldingerDao,
kafkaProducer,
behandlingDao,
Expand All @@ -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,
Expand All @@ -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() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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()
}
Expand Down

0 comments on commit 38a4857

Please sign in to comment.