mirror of
https://github.com/Suwayomi/Tachidesk.git
synced 2026-01-31 16:04:15 +01:00
Fix/updater scheduling auto updates (#615)
* Trigger missed auto global update immediately on server start In case the last execution was missed, it was never immediately scheduled. Thus, it had to be waited for the next scheduled execution to be executed. * Schedule auto global updates at a later point during the startup In case a global update was triggered immediately, the server setup wasn't far enough causing an error due to trying to use things (e.g. database) that weren't initialized yet
This commit is contained in:
@@ -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<UpdateJob> {
|
||||
|
||||
@@ -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()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user