diff --git a/server/src/main/kotlin/suwayomi/tachidesk/manga/impl/update/Updater.kt b/server/src/main/kotlin/suwayomi/tachidesk/manga/impl/update/Updater.kt index ec5d1ee9..ecd754bc 100644 --- a/server/src/main/kotlin/suwayomi/tachidesk/manga/impl/update/Updater.kt +++ b/server/src/main/kotlin/suwayomi/tachidesk/manga/impl/update/Updater.kt @@ -52,10 +52,6 @@ class Updater : IUpdater { private var currentUpdateTaskId = "" - init { - scheduleUpdateTask() - } - private fun autoUpdateTask() { val lastAutomatedUpdate = preferences.getLong(lastAutomatedUpdateKey, 0) preferences.putLong(lastAutomatedUpdateKey, System.currentTimeMillis()) @@ -69,7 +65,7 @@ class Updater : IUpdater { addCategoriesToUpdateQueue(Category.getCategoryList(), true) } - private fun scheduleUpdateTask() { + fun scheduleUpdateTask() { HAScheduler.deschedule(currentUpdateTaskId) val isAutoUpdateDisabled = serverConfig.globalUpdateInterval == 0.0 @@ -79,9 +75,14 @@ class Updater : IUpdater { val updateInterval = serverConfig.globalUpdateInterval.hours.coerceAtLeast(6.hours).inWholeMilliseconds val lastAutomatedUpdate = preferences.getLong(lastAutomatedUpdateKey, 0) - val initialDelay = updateInterval - (System.currentTimeMillis() - lastAutomatedUpdate) % updateInterval + val timeToNextExecution = updateInterval - (System.currentTimeMillis() - lastAutomatedUpdate) % updateInterval - HAScheduler.schedule(::autoUpdateTask, updateInterval, initialDelay, "global-update") + val wasPreviousUpdateTriggered = System.currentTimeMillis() - (if (lastAutomatedUpdate > 0) lastAutomatedUpdate else System.currentTimeMillis()) < updateInterval + if (!wasPreviousUpdateTriggered) { + autoUpdateTask() + } + + HAScheduler.schedule(::autoUpdateTask, updateInterval, timeToNextExecution, "global-update") } private fun getOrCreateUpdateChannelFor(source: String): Channel { diff --git a/server/src/main/kotlin/suwayomi/tachidesk/server/ServerSetup.kt b/server/src/main/kotlin/suwayomi/tachidesk/server/ServerSetup.kt index 067eb4c8..b8c72136 100644 --- a/server/src/main/kotlin/suwayomi/tachidesk/server/ServerSetup.kt +++ b/server/src/main/kotlin/suwayomi/tachidesk/server/ServerSetup.kt @@ -184,6 +184,9 @@ fun applicationSetup() { // AES/CBC/PKCS7Padding Cypher provider for zh.copymanga Security.addProvider(BouncyCastleProvider()) + // start automated global updates + updater.scheduleUpdateTask() + // start automated backups ProtoBackupExport.scheduleAutomatedBackupTask()