Skip to content

Commit

Permalink
IS-2581: Cronjob ukentlig (#334)
Browse files Browse the repository at this point in the history
  • Loading branch information
geir-waagboe authored Aug 13, 2024
1 parent 4947721 commit bed3591
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/main/kotlin/no/nav/syfo/cronjob/CronjobModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ fun cronjobModule(
dialogmeldingStatusCronjob,
verifyPartnerIdCronjob,
suspensjonCronjob,
// verifyBehandlereForKontorCronjob,
verifyBehandlereForKontorCronjob,
).forEach {
launchBackgroundTask(
applicationState = applicationState,
Expand Down
19 changes: 15 additions & 4 deletions src/main/kotlin/no/nav/syfo/cronjob/CronjobUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand All @@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,19 @@ 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(
val behandlerService: BehandlerService,
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()
Expand All @@ -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 {
Expand Down

0 comments on commit bed3591

Please sign in to comment.