Feature/listen to server config value changes (#617)

* Make server config value changes subscribable

* Make server config value changes subscribable - Update usage

* Add util functions to listen to server config value changes

* Listen to server config value changes - Auto backups

* Listen to server config value changes - Auto global update

* Listen to server config value changes - WebUI auto updates

* Listen to server config value changes - Javalin update ip and port

* Listen to server config value changes - Update socks proxy

* Listen to server config value changes - Update debug log level

* Listen to server config value changes - Update system tray icon

* Update config values one at a time

In case settings are changed in quick succession it's possible that each setting update reverts the change of the previous changed setting because the internal config hasn't been updated yet.

E.g.
1. settingA changed
2. settingB changed
3. settingA updates config file
4. settingB updates config file (internal config hasn't been updated yet with change from settingA)
5. settingA updates internal config (settingA updated)
6. settingB updates internal config (settingB updated, settingA outdated)

now settingA is unchanged because settingB reverted its change while updating the config with its new value

* Always add log interceptor to OkHttpClient

In case debug logs are disabled then the KotlinLogging log level will be set to level > debug and thus, these logs won't get logged

* Rename "maxParallelUpdateRequests" to "maxSourcesInParallel"

* Use server setting "maxSourcesInParallel" for downloads

* Listen to server config value changes - downloads

* Always use latest server settings - Browser

* Always use latest server settings - folders

* [Test] Fix type error
This commit is contained in:
schroda
2023-08-12 17:47:41 +02:00
committed by GitHub
parent 01ab912bd9
commit 321fbe22dd
22 changed files with 368 additions and 143 deletions

View File

@@ -8,6 +8,7 @@ package suwayomi.tachidesk.manga.impl.backup.proto
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
import eu.kanade.tachiyomi.source.model.UpdateStrategy
import kotlinx.coroutines.flow.combine
import mu.KotlinLogging
import okio.buffer
import okio.gzip
@@ -53,10 +54,22 @@ object ProtoBackupExport : ProtoBackupBase() {
private const val lastAutomatedBackupKey = "lastAutomatedBackupKey"
private val preferences = Preferences.userNodeForPackage(ProtoBackupExport::class.java)
init {
serverConfig.subscribeTo(
combine(serverConfig.backupInterval, serverConfig.backupTime) { interval, timeOfDay ->
Pair(
interval,
timeOfDay
)
},
::scheduleAutomatedBackupTask
)
}
fun scheduleAutomatedBackupTask() {
HAScheduler.descheduleCron(backupSchedulerJobId)
val areAutomatedBackupsDisabled = serverConfig.backupInterval == 0
val areAutomatedBackupsDisabled = serverConfig.backupInterval.value == 0
if (areAutomatedBackupsDisabled) {
return
}
@@ -67,10 +80,10 @@ object ProtoBackupExport : ProtoBackupBase() {
preferences.putLong(lastAutomatedBackupKey, System.currentTimeMillis())
}
val (hour, minute) = serverConfig.backupTime.split(":").map { it.toInt() }
val (hour, minute) = serverConfig.backupTime.value.split(":").map { it.toInt() }
val backupHour = hour.coerceAtLeast(0).coerceAtMost(23)
val backupMinute = minute.coerceAtLeast(0).coerceAtMost(59)
val backupInterval = serverConfig.backupInterval.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
val lastAutomatedBackup = preferences.getLong(lastAutomatedBackupKey, System.currentTimeMillis())
@@ -105,9 +118,9 @@ object ProtoBackupExport : ProtoBackupBase() {
}
private fun cleanupAutomatedBackups() {
logger.debug { "Cleanup automated backups (ttl= ${serverConfig.backupTTL})" }
logger.debug { "Cleanup automated backups (ttl= ${serverConfig.backupTTL.value})" }
val isCleanupDisabled = serverConfig.backupTTL == 0
val isCleanupDisabled = serverConfig.backupTTL.value == 0
if (isCleanupDisabled) {
return
}
@@ -133,7 +146,7 @@ object ProtoBackupExport : ProtoBackupBase() {
val lastAccessTime = file.lastModified()
val isTTLReached =
System.currentTimeMillis() - lastAccessTime >= serverConfig.backupTTL.days.coerceAtLeast(1.days).inWholeMilliseconds
System.currentTimeMillis() - lastAccessTime >= serverConfig.backupTTL.value.days.coerceAtLeast(1.days).inWholeMilliseconds
if (isTTLReached) {
file.delete()
}