mirror of
https://github.com/Suwayomi/Suwayomi-Server.git
synced 2026-07-13 07:44:34 -05:00
Fix/updater automated update max interval of 23 hours (#606)
* Rename schedule functions * Introduce Base task for "HATask" * Support kotlin Timer repeated interval in HAScheduler It's not possible to schedule a task via cron expression to run every x hours in case the set hours are greater than 23. To be able to do this and still keep the functionality provided by the "HAScheduler" it has to also support repeated tasks scheduled via the default Timer * Support global update interval greater 23 hours * Use "globalUpdateInterval" to disable auto updates Gets rid of an unnecessary setting
This commit is contained in:
@@ -54,7 +54,7 @@ object ProtoBackupExport : ProtoBackupBase() {
|
||||
private val preferences = Preferences.userNodeForPackage(ProtoBackupExport::class.java)
|
||||
|
||||
fun scheduleAutomatedBackupTask() {
|
||||
HAScheduler.deschedule(backupSchedulerJobId)
|
||||
HAScheduler.descheduleCron(backupSchedulerJobId)
|
||||
|
||||
val areAutomatedBackupsDisabled = serverConfig.backupInterval == 0
|
||||
if (areAutomatedBackupsDisabled) {
|
||||
@@ -80,7 +80,7 @@ object ProtoBackupExport : ProtoBackupBase() {
|
||||
task()
|
||||
}
|
||||
|
||||
HAScheduler.schedule(task, "$backupMinute $backupHour */${backupInterval.inWholeDays} * *", "backup")
|
||||
HAScheduler.scheduleCron(task, "$backupMinute $backupHour */${backupInterval.inWholeDays} * *", "backup")
|
||||
}
|
||||
|
||||
private fun createAutomatedBackup() {
|
||||
|
||||
@@ -72,23 +72,16 @@ class Updater : IUpdater {
|
||||
private fun scheduleUpdateTask() {
|
||||
HAScheduler.deschedule(currentUpdateTaskId)
|
||||
|
||||
if (!serverConfig.automaticallyTriggerGlobalUpdate) {
|
||||
val isAutoUpdateDisabled = serverConfig.globalUpdateInterval == 0.0
|
||||
if (isAutoUpdateDisabled) {
|
||||
return
|
||||
}
|
||||
|
||||
val minInterval = 6.hours
|
||||
val interval = serverConfig.globalUpdateInterval.hours
|
||||
val updateInterval = interval.coerceAtLeast(minInterval)
|
||||
val lastAutomatedUpdate = preferences.getLong(lastAutomatedUpdateKey, System.currentTimeMillis())
|
||||
val updateInterval = serverConfig.globalUpdateInterval.hours.coerceAtLeast(6.hours).inWholeMilliseconds
|
||||
val lastAutomatedUpdate = preferences.getLong(lastAutomatedUpdateKey, 0)
|
||||
val initialDelay = updateInterval - (System.currentTimeMillis() - lastAutomatedUpdate) % updateInterval
|
||||
|
||||
// trigger update in case the server wasn't running on the scheduled time
|
||||
val wasPreviousUpdateTriggered =
|
||||
(System.currentTimeMillis() - lastAutomatedUpdate) < updateInterval.inWholeMilliseconds
|
||||
if (!wasPreviousUpdateTriggered) {
|
||||
autoUpdateTask()
|
||||
}
|
||||
|
||||
HAScheduler.schedule(::autoUpdateTask, "0 */${updateInterval.inWholeHours} * * *", "global-update")
|
||||
HAScheduler.schedule(::autoUpdateTask, updateInterval, initialDelay, "global-update")
|
||||
}
|
||||
|
||||
private fun getOrCreateUpdateChannelFor(source: String): Channel<UpdateJob> {
|
||||
|
||||
Reference in New Issue
Block a user