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:
+8
-1
@@ -10,7 +10,11 @@ package suwayomi.tachidesk.manga.impl.backup.proto
|
||||
import android.app.Application
|
||||
import android.content.Context
|
||||
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.launch
|
||||
import mu.KotlinLogging
|
||||
import okio.buffer
|
||||
import okio.gzip
|
||||
@@ -70,6 +74,7 @@ object ProtoBackupExport : ProtoBackupBase() {
|
||||
)
|
||||
}
|
||||
|
||||
@OptIn(DelicateCoroutinesApi::class)
|
||||
fun scheduleAutomatedBackupTask() {
|
||||
HAScheduler.descheduleCron(backupSchedulerJobId)
|
||||
|
||||
@@ -94,7 +99,9 @@ object ProtoBackupExport : ProtoBackupBase() {
|
||||
val wasPreviousBackupTriggered =
|
||||
(System.currentTimeMillis() - lastAutomatedBackup) < backupInterval.inWholeMilliseconds
|
||||
if (!wasPreviousBackupTriggered) {
|
||||
task()
|
||||
GlobalScope.launch(Dispatchers.IO) {
|
||||
task()
|
||||
}
|
||||
}
|
||||
|
||||
HAScheduler.scheduleCron(task, "$backupMinute $backupHour */${backupInterval.inWholeDays} * *", "backup")
|
||||
|
||||
@@ -5,8 +5,10 @@ import android.content.Context
|
||||
import eu.kanade.tachiyomi.source.model.UpdateStrategy
|
||||
import kotlinx.coroutines.CancellationException
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.DelicateCoroutinesApi
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.FlowPreview
|
||||
import kotlinx.coroutines.GlobalScope
|
||||
import kotlinx.coroutines.SupervisorJob
|
||||
import kotlinx.coroutines.cancelChildren
|
||||
import kotlinx.coroutines.channels.BufferOverflow
|
||||
@@ -124,6 +126,7 @@ class Updater : IUpdater {
|
||||
addCategoriesToUpdateQueue(Category.getCategoryList(), clear = true, forceAll = false)
|
||||
}
|
||||
|
||||
@OptIn(DelicateCoroutinesApi::class)
|
||||
fun scheduleUpdateTask() {
|
||||
HAScheduler.deschedule(currentUpdateTaskId)
|
||||
|
||||
@@ -141,7 +144,9 @@ class Updater : IUpdater {
|
||||
if (lastAutomatedUpdate > 0) lastAutomatedUpdate else System.currentTimeMillis()
|
||||
) < updateInterval
|
||||
if (!wasPreviousUpdateTriggered) {
|
||||
autoUpdateTask()
|
||||
GlobalScope.launch {
|
||||
autoUpdateTask()
|
||||
}
|
||||
}
|
||||
|
||||
HAScheduler.schedule(::autoUpdateTask, updateInterval, timeToNextExecution, "global-update")
|
||||
|
||||
@@ -13,8 +13,10 @@ import eu.kanade.tachiyomi.network.GET
|
||||
import eu.kanade.tachiyomi.network.NetworkHelper
|
||||
import eu.kanade.tachiyomi.network.awaitSuccess
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.DelicateCoroutinesApi
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.FlowPreview
|
||||
import kotlinx.coroutines.GlobalScope
|
||||
import kotlinx.coroutines.SupervisorJob
|
||||
import kotlinx.coroutines.channels.BufferOverflow.DROP_OLDEST
|
||||
import kotlinx.coroutines.flow.MutableSharedFlow
|
||||
@@ -234,6 +236,7 @@ object WebInterfaceManager {
|
||||
return serverConfig.webUIUpdateCheckInterval.value.toInt() != 0
|
||||
}
|
||||
|
||||
@OptIn(DelicateCoroutinesApi::class)
|
||||
private fun scheduleWebUIUpdateCheck() {
|
||||
HAScheduler.descheduleCron(currentUpdateTaskId)
|
||||
|
||||
@@ -266,7 +269,9 @@ object WebInterfaceManager {
|
||||
val wasPreviousUpdateCheckTriggered =
|
||||
(System.currentTimeMillis() - lastAutomatedUpdate) < updateInterval.inWholeMilliseconds
|
||||
if (!wasPreviousUpdateCheckTriggered) {
|
||||
task()
|
||||
GlobalScope.launch(Dispatchers.IO) {
|
||||
task()
|
||||
}
|
||||
}
|
||||
|
||||
currentUpdateTaskId =
|
||||
|
||||
Reference in New Issue
Block a user