mirror of
https://github.com/gotson/komga.git
synced 2025-12-20 15:34:17 +01:00
feat(api): cancel all tasks
This commit is contained in:
parent
2395f6e3ac
commit
aff4418256
2 changed files with 45 additions and 0 deletions
|
|
@ -0,0 +1,21 @@
|
|||
package org.gotson.komga.infrastructure.jms
|
||||
|
||||
import mu.KotlinLogging
|
||||
import org.apache.activemq.artemis.api.core.management.QueueControl
|
||||
import org.apache.activemq.artemis.api.core.management.ResourceNames
|
||||
import org.apache.activemq.artemis.core.server.embedded.EmbeddedActiveMQ
|
||||
import org.springframework.stereotype.Service
|
||||
|
||||
private val logger = KotlinLogging.logger {}
|
||||
|
||||
@Service
|
||||
class JmsQueueLifecycle(
|
||||
embeddedActiveMQ: EmbeddedActiveMQ,
|
||||
) {
|
||||
|
||||
private val queueControl = embeddedActiveMQ.activeMQServer.managementService.getResource("${ResourceNames.QUEUE}$QUEUE_TASKS") as QueueControl
|
||||
|
||||
fun emptyTaskQueue(): Int =
|
||||
queueControl.removeAllMessages()
|
||||
.also { logger.info { "Removed $it messages from $QUEUE_TASKS" } }
|
||||
}
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
package org.gotson.komga.interfaces.rest
|
||||
|
||||
import org.gotson.komga.domain.model.ROLE_ADMIN
|
||||
import org.gotson.komga.infrastructure.jms.JmsQueueLifecycle
|
||||
import org.springframework.http.HttpStatus
|
||||
import org.springframework.http.MediaType
|
||||
import org.springframework.security.access.prepost.PreAuthorize
|
||||
import org.springframework.web.bind.annotation.DeleteMapping
|
||||
import org.springframework.web.bind.annotation.RequestMapping
|
||||
import org.springframework.web.bind.annotation.ResponseStatus
|
||||
import org.springframework.web.bind.annotation.RestController
|
||||
|
||||
@RestController
|
||||
@RequestMapping(produces = [MediaType.APPLICATION_JSON_VALUE])
|
||||
class TaskController(
|
||||
private val jmsQueueLifecycle: JmsQueueLifecycle,
|
||||
) {
|
||||
|
||||
@DeleteMapping("api/v1/tasks")
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
@PreAuthorize("hasRole('$ROLE_ADMIN')")
|
||||
fun emptyTaskQueue(): Int =
|
||||
jmsQueueLifecycle.emptyTaskQueue()
|
||||
}
|
||||
Loading…
Reference in a new issue