diff --git a/src/main/kotlin/no/nav/syfo/cronjob/CronjobModule.kt b/src/main/kotlin/no/nav/syfo/cronjob/CronjobModule.kt index 526e5f25..987ec1bb 100644 --- a/src/main/kotlin/no/nav/syfo/cronjob/CronjobModule.kt +++ b/src/main/kotlin/no/nav/syfo/cronjob/CronjobModule.kt @@ -60,7 +60,7 @@ fun cronjobModule( dialogmeldingStatusCronjob, verifyPartnerIdCronjob, suspensjonCronjob, - // verifyBehandlereForKontorCronjob, + verifyBehandlereForKontorCronjob, ).forEach { launchBackgroundTask( applicationState = applicationState, diff --git a/src/main/kotlin/no/nav/syfo/cronjob/CronjobUtils.kt b/src/main/kotlin/no/nav/syfo/cronjob/CronjobUtils.kt index 3a896f4f..b040fc74 100644 --- a/src/main/kotlin/no/nav/syfo/cronjob/CronjobUtils.kt +++ b/src/main/kotlin/no/nav/syfo/cronjob/CronjobUtils.kt @@ -2,10 +2,7 @@ package no.nav.syfo.cronjob import org.slf4j.Logger import org.slf4j.LoggerFactory -import java.time.Duration -import java.time.LocalDate -import java.time.LocalDateTime -import java.time.LocalTime +import java.time.* internal val log: Logger = LoggerFactory.getLogger("no.nav.syfo.cronjob.CronjobUtils") @@ -20,3 +17,17 @@ fun calculateInitialDelay(cronJobName: String, runAtHour: Int): Long { log.info("$cronJobName will run in $initialDelay minutes at $nextTimeToRun") return initialDelay } + +fun calculateWeeklyInitialDelay(cronJobName: String, runDay: DayOfWeek, runAtHour: Int): Long { + val from = LocalDateTime.now() + val nowDate = LocalDate.now() + val nowDay = nowDate.dayOfWeek + val daysUntilRunDay = if (nowDay <= runDay) (runDay.value - nowDay.value) else (7 - nowDay.value + runDay.value) + val nextTimeToRun = LocalDateTime.of( + nowDate.plusDays(if (daysUntilRunDay == 0 && runAtHour < from.hour) 7 else daysUntilRunDay.toLong()), + LocalTime.of(runAtHour, 0), + ) + val initialDelay = Duration.between(from, nextTimeToRun).toMinutes() + log.info("$cronJobName will run in $initialDelay minutes at $nextTimeToRun") + return initialDelay +} diff --git a/src/main/kotlin/no/nav/syfo/cronjob/VerifyBehandlereForKontorCronjob.kt b/src/main/kotlin/no/nav/syfo/cronjob/VerifyBehandlereForKontorCronjob.kt index c0803e55..9acd4fc0 100644 --- a/src/main/kotlin/no/nav/syfo/cronjob/VerifyBehandlereForKontorCronjob.kt +++ b/src/main/kotlin/no/nav/syfo/cronjob/VerifyBehandlereForKontorCronjob.kt @@ -15,6 +15,7 @@ import no.nav.syfo.domain.Personident import no.nav.syfo.domain.isDNR import no.nav.syfo.util.nowUTC import org.slf4j.LoggerFactory +import java.time.DayOfWeek import java.util.UUID class VerifyBehandlereForKontorCronjob( @@ -22,10 +23,11 @@ class VerifyBehandlereForKontorCronjob( val fastlegeClient: FastlegeClient, val syfohelsenettproxyClient: SyfohelsenettproxyClient, ) : DialogmeldingCronjob { - private val runAtHour = 12 + private val runAtHour = 6 + private val runDay = DayOfWeek.SUNDAY - override val initialDelayMinutes: Long = calculateInitialDelay("VerifyBehandlereForKontorCronjob", runAtHour) - override val intervalDelayMinutes: Long = 24 * 60 + override val initialDelayMinutes: Long = calculateWeeklyInitialDelay("VerifyBehandlereForKontorCronjob", runDay, runAtHour) + override val intervalDelayMinutes: Long = 24 * 60 * 7 override suspend fun run() { verifyBehandlereForKontorJob() @@ -35,7 +37,7 @@ class VerifyBehandlereForKontorCronjob( val verifyResult = DialogmeldingCronjobResult() val behandlerKontorListe = behandlerService.getKontor().filter { - it.herId != null && it.dialogmeldingEnabled != null && (it.herId == "1841" || it.herId == "50031" || it.herId == "2543" || it.herId == "175469") + it.herId != null && it.dialogmeldingEnabled != null } behandlerKontorListe.forEach { behandlerKontor -> try {