Updater cleanup and improvements (#416)
This commit is contained in:
@@ -32,7 +32,7 @@ internal class UpdateControllerTest : ApplicationTest() {
|
||||
UpdateController.categoryUpdate(ctx)
|
||||
verify { ctx.status(HttpCode.BAD_REQUEST) }
|
||||
val updater by DI.global.instance<IUpdater>()
|
||||
assertEquals(0, updater.getStatus().value.numberOfJobs)
|
||||
assertEquals(0, updater.status.value.numberOfJobs)
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -44,7 +44,7 @@ internal class UpdateControllerTest : ApplicationTest() {
|
||||
UpdateController.categoryUpdate(ctx)
|
||||
verify { ctx.status(HttpCode.OK) }
|
||||
val updater by DI.global.instance<IUpdater>()
|
||||
assertEquals(1, updater.getStatus().value.numberOfJobs)
|
||||
assertEquals(1, updater.status.value.numberOfJobs)
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -60,7 +60,7 @@ internal class UpdateControllerTest : ApplicationTest() {
|
||||
UpdateController.categoryUpdate(ctx)
|
||||
verify { ctx.status(HttpCode.OK) }
|
||||
val updater by DI.global.instance<IUpdater>()
|
||||
assertEquals(3, updater.getStatus().value.numberOfJobs)
|
||||
assertEquals(3, updater.status.value.numberOfJobs)
|
||||
}
|
||||
|
||||
private fun createLibraryManga(
|
||||
|
||||
@@ -2,23 +2,30 @@ package suwayomi.tachidesk.manga.impl.update
|
||||
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.asStateFlow
|
||||
import kotlinx.coroutines.flow.update
|
||||
import suwayomi.tachidesk.manga.model.dataclass.MangaDataClass
|
||||
import java.util.concurrent.CopyOnWriteArrayList
|
||||
|
||||
class TestUpdater : IUpdater {
|
||||
private val updateQueue = ArrayList<UpdateJob>()
|
||||
private val updateQueue = CopyOnWriteArrayList<UpdateJob>()
|
||||
private var isRunning = false
|
||||
private val _status = MutableStateFlow(UpdateStatus())
|
||||
override val status: StateFlow<UpdateStatus> = _status.asStateFlow()
|
||||
|
||||
override fun addMangaToQueue(manga: MangaDataClass) {
|
||||
updateQueue.add(UpdateJob(manga))
|
||||
isRunning = true
|
||||
updateStatus()
|
||||
}
|
||||
|
||||
override fun getStatus(): StateFlow<UpdateStatus> {
|
||||
return MutableStateFlow(UpdateStatus(updateQueue, isRunning))
|
||||
}
|
||||
|
||||
override suspend fun reset() {
|
||||
override fun reset() {
|
||||
updateQueue.clear()
|
||||
isRunning = false
|
||||
updateStatus()
|
||||
}
|
||||
|
||||
private fun updateStatus() {
|
||||
_status.update { UpdateStatus(updateQueue.toList(), isRunning) }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user