Skip to content

Commit

Permalink
Support global update interval greater 23 hours
Browse files Browse the repository at this point in the history
  • Loading branch information
schroda committed Jul 22, 2023
1 parent 9be5d6b commit f024a06
Showing 1 changed file with 5 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,25 +70,17 @@ class Updater : IUpdater {
}

private fun scheduleUpdateTask() {
HAScheduler.descheduleCron(currentUpdateTaskId)
HAScheduler.deschedule(currentUpdateTaskId)

if (!serverConfig.automaticallyTriggerGlobalUpdate) {
return
}

val minInterval = 6.hours
val interval = serverConfig.globalUpdateInterval.hours
val updateInterval = interval.coerceAtLeast(minInterval)
val lastAutomatedUpdate = preferences.getLong(lastAutomatedUpdateKey, System.currentTimeMillis())

// trigger update in case the server wasn't running on the scheduled time
val wasPreviousUpdateTriggered =
(System.currentTimeMillis() - lastAutomatedUpdate) < updateInterval.inWholeMilliseconds
if (!wasPreviousUpdateTriggered) {
autoUpdateTask()
}
val updateInterval = serverConfig.globalUpdateInterval.hours.coerceAtLeast(6.hours).inWholeMilliseconds
val lastAutomatedUpdate = preferences.getLong(lastAutomatedUpdateKey, 0)
val initialDelay = updateInterval - (System.currentTimeMillis() - lastAutomatedUpdate) % updateInterval

HAScheduler.scheduleCron(::autoUpdateTask, "0 */${updateInterval.inWholeHours} * * *", "global-update")
HAScheduler.schedule(::autoUpdateTask, updateInterval, initialDelay, "global-update")
}

private fun getOrCreateUpdateChannelFor(source: String): Channel<UpdateJob> {
Expand Down

0 comments on commit f024a06

Please sign in to comment.