diff --git a/komga/src/main/kotlin/org/gotson/komga/application/tasks/TaskReceiver.kt b/komga/src/main/kotlin/org/gotson/komga/application/tasks/TaskReceiver.kt index 069002ff5..ffb54fbc9 100644 --- a/komga/src/main/kotlin/org/gotson/komga/application/tasks/TaskReceiver.kt +++ b/komga/src/main/kotlin/org/gotson/komga/application/tasks/TaskReceiver.kt @@ -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) } } } diff --git a/komga/src/main/kotlin/org/gotson/komga/infrastructure/jms/ArtemisConfig.kt b/komga/src/main/kotlin/org/gotson/komga/infrastructure/jms/ArtemisConfig.kt index 176e07fc1..423a6e8ef 100644 --- a/komga/src/main/kotlin/org/gotson/komga/infrastructure/jms/ArtemisConfig.kt +++ b/komga/src/main/kotlin/org/gotson/komga/infrastructure/jms/ArtemisConfig.kt @@ -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" diff --git a/komga/src/main/kotlin/org/gotson/komga/interfaces/sse/SseController.kt b/komga/src/main/kotlin/org/gotson/komga/interfaces/sse/SseController.kt index c11795cae..e17c61888 100644 --- a/komga/src/main/kotlin/org/gotson/komga/interfaces/sse/SseController.kt +++ b/komga/src/main/kotlin/org/gotson/komga/interfaces/sse/SseController.kt @@ -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) diff --git a/komga/src/main/kotlin/org/gotson/komga/interfaces/sse/dto/TaskQueueSseDto.kt b/komga/src/main/kotlin/org/gotson/komga/interfaces/sse/dto/TaskQueueSseDto.kt index d2402857a..357531c0b 100644 --- a/komga/src/main/kotlin/org/gotson/komga/interfaces/sse/dto/TaskQueueSseDto.kt +++ b/komga/src/main/kotlin/org/gotson/komga/interfaces/sse/dto/TaskQueueSseDto.kt @@ -2,4 +2,5 @@ package org.gotson.komga.interfaces.sse.dto data class TaskQueueSseDto( val count: Int, + val countByType: Map )