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
This commit is contained in:
schroda
2023-11-06 03:16:48 +01:00
committed by GitHub
parent 05bf4f5525
commit 7993da038e
3 changed files with 8 additions and 8 deletions

View File

@@ -54,8 +54,8 @@ object ProtoBackupExport : ProtoBackupBase() {
private val logger = KotlinLogging.logger { } private val logger = KotlinLogging.logger { }
private val applicationDirs by DI.global.instance<ApplicationDirs>() private val applicationDirs by DI.global.instance<ApplicationDirs>()
private var backupSchedulerJobId: String = "" private var backupSchedulerJobId: String = ""
private const val LAST_AUTOMATED_BACKUP_KEY = "lastAutomatedBackupKey" private const val LAST_AUTOMATED_BACKUP_KEY = "lastAutomatedBackup"
private val preferences = Injekt.get<Application>().getSharedPreferences("manga/impl/backup/proto", Context.MODE_PRIVATE) private val preferences = Injekt.get<Application>().getSharedPreferences("server_util", Context.MODE_PRIVATE)
init { init {
serverConfig.subscribeTo( serverConfig.subscribeTo(
@@ -89,7 +89,7 @@ object ProtoBackupExport : ProtoBackupBase() {
val backupInterval = serverConfig.backupInterval.value.days.coerceAtLeast(1.days) val backupInterval = serverConfig.backupInterval.value.days.coerceAtLeast(1.days)
// trigger last backup in case the server wasn't running on the scheduled time // 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 = val wasPreviousBackupTriggered =
(System.currentTimeMillis() - lastAutomatedBackup) < backupInterval.inWholeMilliseconds (System.currentTimeMillis() - lastAutomatedBackup) < backupInterval.inWholeMilliseconds
if (!wasPreviousBackupTriggered) { if (!wasPreviousBackupTriggered) {

View File

@@ -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 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 semaphore = Semaphore(maxSourcesInParallel)
private val lastUpdateKey = "lastUpdateKey" private val lastUpdateKey = "lastGlobalUpdate"
private val lastAutomatedUpdateKey = "lastAutomatedUpdateKey" private val lastAutomatedUpdateKey = "lastAutomatedGlobalUpdate"
private val preferences = Injekt.get<Application>().getSharedPreferences("manga/impl/update", Context.MODE_PRIVATE) private val preferences = Injekt.get<Application>().getSharedPreferences("server_util", Context.MODE_PRIVATE)
private var currentUpdateTaskId = "" private var currentUpdateTaskId = ""

View File

@@ -125,9 +125,9 @@ object WebInterfaceManager {
private val logger = KotlinLogging.logger {} private val logger = KotlinLogging.logger {}
private val scope = CoroutineScope(SupervisorJob() + Dispatchers.Default) 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<Application>().getSharedPreferences("server/util", Context.MODE_PRIVATE) private val preferences = Injekt.get<Application>().getSharedPreferences("server_util", Context.MODE_PRIVATE)
private var currentUpdateTaskId: String = "" private var currentUpdateTaskId: String = ""
private val json: Json by injectLazy() private val json: Json by injectLazy()