mirror of
https://github.com/Suwayomi/Suwayomi-Server.git
synced 2026-07-04 11:24:35 -05:00
Fix/backup import failure not resetting status (#746)
* Reset backup status to idle in case of an exception * Rename "performRestore" function * Set backup status to failure on exception Makes it possible to detect if the restore failed or not after the first status was received * Set backup status to success on completion Since the status is not provided over a subscription, but over a query that should be pulled, it is not really easily detectable if a restore finished or not, since both states will be indicated by "idle" * Correctly wait for first new status when triggering backup import The status is only "Idle" in case no backup import has ever run. Once the first backup process finished it is either "Failure" or "Success" * Rename "ProtoBackupImport::restore" function * Add id to restore process Makes it possible to differentiate between backup restore processes.
This commit is contained in:
@@ -1,13 +1,9 @@
|
||||
package suwayomi.tachidesk.graphql.mutations
|
||||
|
||||
import io.javalin.http.UploadedFile
|
||||
import kotlinx.coroutines.DelicateCoroutinesApi
|
||||
import kotlinx.coroutines.GlobalScope
|
||||
import kotlinx.coroutines.flow.first
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withTimeout
|
||||
import suwayomi.tachidesk.graphql.server.TemporaryFileStorage
|
||||
import suwayomi.tachidesk.graphql.types.BackupRestoreState
|
||||
import suwayomi.tachidesk.graphql.types.BackupRestoreStatus
|
||||
import suwayomi.tachidesk.graphql.types.toStatus
|
||||
import suwayomi.tachidesk.manga.impl.backup.BackupFlags
|
||||
@@ -25,26 +21,23 @@ class BackupMutation {
|
||||
|
||||
data class RestoreBackupPayload(
|
||||
val clientMutationId: String?,
|
||||
val status: BackupRestoreStatus,
|
||||
val id: String,
|
||||
val status: BackupRestoreStatus?,
|
||||
)
|
||||
|
||||
@OptIn(DelicateCoroutinesApi::class)
|
||||
fun restoreBackup(input: RestoreBackupInput): CompletableFuture<RestoreBackupPayload> {
|
||||
val (clientMutationId, backup) = input
|
||||
|
||||
return future {
|
||||
GlobalScope.launch {
|
||||
ProtoBackupImport.performRestore(backup.content)
|
||||
val restoreId = ProtoBackupImport.restore(backup.content)
|
||||
|
||||
withTimeout(10.seconds) {
|
||||
ProtoBackupImport.notifyFlow.first {
|
||||
ProtoBackupImport.getRestoreState(restoreId) != null
|
||||
}
|
||||
}
|
||||
|
||||
val status =
|
||||
withTimeout(10.seconds) {
|
||||
ProtoBackupImport.backupRestoreState.first {
|
||||
it != ProtoBackupImport.BackupRestoreState.Idle
|
||||
}.toStatus()
|
||||
}
|
||||
|
||||
RestoreBackupPayload(clientMutationId, status)
|
||||
RestoreBackupPayload(clientMutationId, restoreId, ProtoBackupImport.getRestoreState(restoreId)?.toStatus())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user