From 7993da038e4d5723e33a182e68b72888b5ec4728 Mon Sep 17 00:00:00 2001 From: schroda <50052685+schroda@users.noreply.github.com> Date: Mon, 6 Nov 2023 03:16:48 +0100 Subject: [PATCH] Fix/initial auto backup never triggered in case server was not running (#762) * Trigger initial auto backup in case server was not running In case the server was not started (stopped, system shutdown - not in hibernation) during the scheduled auto backup time, the auto backup never got triggered. * Update server util preferences --- .../tachidesk/manga/impl/backup/proto/ProtoBackupExport.kt | 6 +++--- .../kotlin/suwayomi/tachidesk/manga/impl/update/Updater.kt | 6 +++--- .../suwayomi/tachidesk/server/util/WebInterfaceManager.kt | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/server/src/main/kotlin/suwayomi/tachidesk/manga/impl/backup/proto/ProtoBackupExport.kt b/server/src/main/kotlin/suwayomi/tachidesk/manga/impl/backup/proto/ProtoBackupExport.kt index 37c00047..4a35f683 100644 --- a/server/src/main/kotlin/suwayomi/tachidesk/manga/impl/backup/proto/ProtoBackupExport.kt +++ b/server/src/main/kotlin/suwayomi/tachidesk/manga/impl/backup/proto/ProtoBackupExport.kt @@ -54,8 +54,8 @@ object ProtoBackupExport : ProtoBackupBase() { private val logger = KotlinLogging.logger { } private val applicationDirs by DI.global.instance() private var backupSchedulerJobId: String = "" - private const val LAST_AUTOMATED_BACKUP_KEY = "lastAutomatedBackupKey" - private val preferences = Injekt.get().getSharedPreferences("manga/impl/backup/proto", Context.MODE_PRIVATE) + private const val LAST_AUTOMATED_BACKUP_KEY = "lastAutomatedBackup" + private val preferences = Injekt.get().getSharedPreferences("server_util", Context.MODE_PRIVATE) init { serverConfig.subscribeTo( @@ -89,7 +89,7 @@ object ProtoBackupExport : ProtoBackupBase() { val backupInterval = serverConfig.backupInterval.value.days.coerceAtLeast(1.days) // trigger last backup in case the server wasn't running on the scheduled time - val lastAutomatedBackup = preferences.getLong(LAST_AUTOMATED_BACKUP_KEY, System.currentTimeMillis()) + val lastAutomatedBackup = preferences.getLong(LAST_AUTOMATED_BACKUP_KEY, 0) val wasPreviousBackupTriggered = (System.currentTimeMillis() - lastAutomatedBackup) < backupInterval.inWholeMilliseconds if (!wasPreviousBackupTriggered) { 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 c7ccf5d3..350e24ce 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 @@ -51,9 +51,9 @@ class Updater : IUpdater { private var maxSourcesInParallel = 20 // max permits, necessary to be set to be able to release up to 20 permits private val semaphore = Semaphore(maxSourcesInParallel) - private val lastUpdateKey = "lastUpdateKey" - private val lastAutomatedUpdateKey = "lastAutomatedUpdateKey" - private val preferences = Injekt.get().getSharedPreferences("manga/impl/update", Context.MODE_PRIVATE) + private val lastUpdateKey = "lastGlobalUpdate" + private val lastAutomatedUpdateKey = "lastAutomatedGlobalUpdate" + private val preferences = Injekt.get().getSharedPreferences("server_util", Context.MODE_PRIVATE) private var currentUpdateTaskId = "" diff --git a/server/src/main/kotlin/suwayomi/tachidesk/server/util/WebInterfaceManager.kt b/server/src/main/kotlin/suwayomi/tachidesk/server/util/WebInterfaceManager.kt index 5b78072a..8db04bdc 100644 --- a/server/src/main/kotlin/suwayomi/tachidesk/server/util/WebInterfaceManager.kt +++ b/server/src/main/kotlin/suwayomi/tachidesk/server/util/WebInterfaceManager.kt @@ -125,9 +125,9 @@ object WebInterfaceManager { private val logger = KotlinLogging.logger {} private val scope = CoroutineScope(SupervisorJob() + Dispatchers.Default) - private const val LAST_WEBUI_UPDATE_CHECK_KEY = "lastWebUIUpdateCheckKey" + private const val LAST_WEBUI_UPDATE_CHECK_KEY = "lastWebUIUpdateCheck" - private val preferences = Injekt.get().getSharedPreferences("server/util", Context.MODE_PRIVATE) + private val preferences = Injekt.get().getSharedPreferences("server_util", Context.MODE_PRIVATE) private var currentUpdateTaskId: String = "" private val json: Json by injectLazy()