Fix/server startup blocked by synchronous tasks (#1018)

* Launch missed auto backup task in background

* Launch missed auto global update task in background

* Launch missed auto webui update check task in background
This commit is contained in:
schroda
2024-09-01 00:54:41 +02:00
committed by GitHub
parent 5b08b81239
commit 9a1e4df408
3 changed files with 20 additions and 3 deletions

View File

@@ -10,7 +10,11 @@ package suwayomi.tachidesk.manga.impl.backup.proto
import android.app.Application import android.app.Application
import android.content.Context import android.content.Context
import eu.kanade.tachiyomi.source.model.UpdateStrategy import eu.kanade.tachiyomi.source.model.UpdateStrategy
import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.flow.combine import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.launch
import mu.KotlinLogging import mu.KotlinLogging
import okio.buffer import okio.buffer
import okio.gzip import okio.gzip
@@ -70,6 +74,7 @@ object ProtoBackupExport : ProtoBackupBase() {
) )
} }
@OptIn(DelicateCoroutinesApi::class)
fun scheduleAutomatedBackupTask() { fun scheduleAutomatedBackupTask() {
HAScheduler.descheduleCron(backupSchedulerJobId) HAScheduler.descheduleCron(backupSchedulerJobId)
@@ -94,7 +99,9 @@ object ProtoBackupExport : ProtoBackupBase() {
val wasPreviousBackupTriggered = val wasPreviousBackupTriggered =
(System.currentTimeMillis() - lastAutomatedBackup) < backupInterval.inWholeMilliseconds (System.currentTimeMillis() - lastAutomatedBackup) < backupInterval.inWholeMilliseconds
if (!wasPreviousBackupTriggered) { if (!wasPreviousBackupTriggered) {
task() GlobalScope.launch(Dispatchers.IO) {
task()
}
} }
HAScheduler.scheduleCron(task, "$backupMinute $backupHour */${backupInterval.inWholeDays} * *", "backup") HAScheduler.scheduleCron(task, "$backupMinute $backupHour */${backupInterval.inWholeDays} * *", "backup")

View File

@@ -5,8 +5,10 @@ import android.content.Context
import eu.kanade.tachiyomi.source.model.UpdateStrategy import eu.kanade.tachiyomi.source.model.UpdateStrategy
import kotlinx.coroutines.CancellationException import kotlinx.coroutines.CancellationException
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.FlowPreview import kotlinx.coroutines.FlowPreview
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.SupervisorJob import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.cancelChildren import kotlinx.coroutines.cancelChildren
import kotlinx.coroutines.channels.BufferOverflow import kotlinx.coroutines.channels.BufferOverflow
@@ -124,6 +126,7 @@ class Updater : IUpdater {
addCategoriesToUpdateQueue(Category.getCategoryList(), clear = true, forceAll = false) addCategoriesToUpdateQueue(Category.getCategoryList(), clear = true, forceAll = false)
} }
@OptIn(DelicateCoroutinesApi::class)
fun scheduleUpdateTask() { fun scheduleUpdateTask() {
HAScheduler.deschedule(currentUpdateTaskId) HAScheduler.deschedule(currentUpdateTaskId)
@@ -141,7 +144,9 @@ class Updater : IUpdater {
if (lastAutomatedUpdate > 0) lastAutomatedUpdate else System.currentTimeMillis() if (lastAutomatedUpdate > 0) lastAutomatedUpdate else System.currentTimeMillis()
) < updateInterval ) < updateInterval
if (!wasPreviousUpdateTriggered) { if (!wasPreviousUpdateTriggered) {
autoUpdateTask() GlobalScope.launch {
autoUpdateTask()
}
} }
HAScheduler.schedule(::autoUpdateTask, updateInterval, timeToNextExecution, "global-update") HAScheduler.schedule(::autoUpdateTask, updateInterval, timeToNextExecution, "global-update")

View File

@@ -13,8 +13,10 @@ import eu.kanade.tachiyomi.network.GET
import eu.kanade.tachiyomi.network.NetworkHelper import eu.kanade.tachiyomi.network.NetworkHelper
import eu.kanade.tachiyomi.network.awaitSuccess import eu.kanade.tachiyomi.network.awaitSuccess
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.FlowPreview import kotlinx.coroutines.FlowPreview
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.SupervisorJob import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.channels.BufferOverflow.DROP_OLDEST import kotlinx.coroutines.channels.BufferOverflow.DROP_OLDEST
import kotlinx.coroutines.flow.MutableSharedFlow import kotlinx.coroutines.flow.MutableSharedFlow
@@ -234,6 +236,7 @@ object WebInterfaceManager {
return serverConfig.webUIUpdateCheckInterval.value.toInt() != 0 return serverConfig.webUIUpdateCheckInterval.value.toInt() != 0
} }
@OptIn(DelicateCoroutinesApi::class)
private fun scheduleWebUIUpdateCheck() { private fun scheduleWebUIUpdateCheck() {
HAScheduler.descheduleCron(currentUpdateTaskId) HAScheduler.descheduleCron(currentUpdateTaskId)
@@ -266,7 +269,9 @@ object WebInterfaceManager {
val wasPreviousUpdateCheckTriggered = val wasPreviousUpdateCheckTriggered =
(System.currentTimeMillis() - lastAutomatedUpdate) < updateInterval.inWholeMilliseconds (System.currentTimeMillis() - lastAutomatedUpdate) < updateInterval.inWholeMilliseconds
if (!wasPreviousUpdateCheckTriggered) { if (!wasPreviousUpdateCheckTriggered) {
task() GlobalScope.launch(Dispatchers.IO) {
task()
}
} }
currentUpdateTaskId = currentUpdateTaskId =