mirror of
https://github.com/gotson/komga.git
synced 2025-12-20 15:34:17 +01:00
feat(sse): publish breakdown of task count by task type
This commit is contained in:
parent
547167feb5
commit
eda767aeb5
4 changed files with 14 additions and 4 deletions
|
|
@ -9,6 +9,7 @@ import org.gotson.komga.domain.model.Media
|
|||
import org.gotson.komga.domain.persistence.BookRepository
|
||||
import org.gotson.komga.domain.persistence.LibraryRepository
|
||||
import org.gotson.komga.domain.service.BookConverter
|
||||
import org.gotson.komga.infrastructure.jms.QUEUE_SUB_TYPE
|
||||
import org.gotson.komga.infrastructure.jms.QUEUE_TASKS
|
||||
import org.gotson.komga.infrastructure.jms.QUEUE_TASKS_TYPE
|
||||
import org.gotson.komga.infrastructure.jms.QUEUE_TYPE
|
||||
|
|
@ -109,6 +110,7 @@ class TaskReceiver(
|
|||
it.apply {
|
||||
setStringProperty(QUEUE_TYPE, QUEUE_TASKS_TYPE)
|
||||
setStringProperty(QUEUE_UNIQUE_ID, task.uniqueId())
|
||||
setStringProperty(QUEUE_SUB_TYPE, task::class.simpleName)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ import org.apache.activemq.artemis.core.config.Configuration as ArtemisConfigura
|
|||
|
||||
const val QUEUE_UNIQUE_ID = "unique_id"
|
||||
const val QUEUE_TYPE = "type"
|
||||
const val QUEUE_SUB_TYPE = "subtype"
|
||||
|
||||
const val QUEUE_TASKS = "tasks.background"
|
||||
const val QUEUE_TASKS_TYPE = "task"
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import org.gotson.komga.domain.model.KomgaUser
|
|||
import org.gotson.komga.domain.persistence.BookRepository
|
||||
import org.gotson.komga.infrastructure.jms.QUEUE_SSE
|
||||
import org.gotson.komga.infrastructure.jms.QUEUE_SSE_SELECTOR
|
||||
import org.gotson.komga.infrastructure.jms.QUEUE_SUB_TYPE
|
||||
import org.gotson.komga.infrastructure.jms.QUEUE_TASKS
|
||||
import org.gotson.komga.infrastructure.jms.TOPIC_FACTORY
|
||||
import org.gotson.komga.infrastructure.security.KomgaPrincipal
|
||||
|
|
@ -31,6 +32,7 @@ import org.springframework.web.bind.annotation.GetMapping
|
|||
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter
|
||||
import java.io.IOException
|
||||
import java.util.Collections
|
||||
import javax.jms.ObjectMessage
|
||||
import javax.jms.QueueBrowser
|
||||
import javax.jms.Session
|
||||
|
||||
|
|
@ -57,11 +59,15 @@ class SseController(
|
|||
|
||||
@Scheduled(fixedRate = 10_000)
|
||||
fun taskCount() {
|
||||
val size = jmsTemplate.browse(QUEUE_TASKS) { _: Session, browser: QueueBrowser ->
|
||||
browser.enumeration.toList().size
|
||||
} ?: 0
|
||||
if (emitters.isNotEmpty()) {
|
||||
val tasksCount = jmsTemplate.browse(QUEUE_TASKS) { _: Session, browser: QueueBrowser ->
|
||||
browser.enumeration.toList()
|
||||
.groupingBy { (it as ObjectMessage).getStringProperty(QUEUE_SUB_TYPE) ?: "unknown" }
|
||||
.eachCount()
|
||||
} ?: emptyMap()
|
||||
|
||||
emitSse("TaskQueueStatus", TaskQueueSseDto(size), adminOnly = true)
|
||||
emitSse("TaskQueueStatus", TaskQueueSseDto(tasksCount.values.sum(), tasksCount), adminOnly = true)
|
||||
}
|
||||
}
|
||||
|
||||
@JmsListener(destination = QUEUE_SSE, selector = QUEUE_SSE_SELECTOR, containerFactory = TOPIC_FACTORY)
|
||||
|
|
|
|||
|
|
@ -2,4 +2,5 @@ package org.gotson.komga.interfaces.sse.dto
|
|||
|
||||
data class TaskQueueSseDto(
|
||||
val count: Int,
|
||||
val countByType: Map<String, Int>
|
||||
)
|
||||
|
|
|
|||
Loading…
Reference in a new issue