From 27f45ded9136aff5763bc85c1734bdcc601f5f3a Mon Sep 17 00:00:00 2001 From: bskjon Date: Sun, 18 Aug 2024 20:18:15 +0200 Subject: [PATCH] Reduced logging and replaced with controller --- .../coordinator/controller/PollController.kt | 18 ++++++++++++++++++ .../eventi/implementations/EventCoordinator.kt | 12 +++++++----- 2 files changed, 25 insertions(+), 5 deletions(-) create mode 100644 apps/coordinator/src/main/kotlin/no/iktdev/mediaprocessing/coordinator/controller/PollController.kt diff --git a/apps/coordinator/src/main/kotlin/no/iktdev/mediaprocessing/coordinator/controller/PollController.kt b/apps/coordinator/src/main/kotlin/no/iktdev/mediaprocessing/coordinator/controller/PollController.kt new file mode 100644 index 00000000..0e706023 --- /dev/null +++ b/apps/coordinator/src/main/kotlin/no/iktdev/mediaprocessing/coordinator/controller/PollController.kt @@ -0,0 +1,18 @@ +package no.iktdev.mediaprocessing.coordinator.controller + +import no.iktdev.mediaprocessing.coordinator.Coordinator +import org.springframework.beans.factory.annotation.Autowired +import org.springframework.stereotype.Controller +import org.springframework.web.bind.annotation.GetMapping +import org.springframework.web.bind.annotation.RequestMapping + +@Controller +@RequestMapping(path = ["/polls"]) +class PollController(@Autowired var coordinator: Coordinator) { + + @GetMapping() + fun polls(): String { + val stat = coordinator.getActivePolls() + return "Active Polls ${stat.active}/${stat.total}" + } +} diff --git a/shared/eventi/src/main/kotlin/no/iktdev/eventi/implementations/EventCoordinator.kt b/shared/eventi/src/main/kotlin/no/iktdev/eventi/implementations/EventCoordinator.kt index ce80506a..bf75f0de 100644 --- a/shared/eventi/src/main/kotlin/no/iktdev/eventi/implementations/EventCoordinator.kt +++ b/shared/eventi/src/main/kotlin/no/iktdev/eventi/implementations/EventCoordinator.kt @@ -45,21 +45,23 @@ abstract class EventCoordinator> { abstract fun getActiveTaskMode(): ActiveMode - + private var activePolls: Int = 0 + data class PollStats(val active: Int, val total: Int) + fun getActivePolls(): PollStats { + return PollStats(active = activePolls, total = referencePool.values.size) + } private fun onEventGroupsReceived(eventGroup: List>) { val egRefIds = eventGroup.map { it.first().referenceId() } val orphanedReferences = referencePool.filter { !it.value.isActive }.filter { id -> id.key !in egRefIds }.map { it.key } orphanedReferences.forEach { id -> referencePool.remove(id) } - val activePolls = referencePool.values.filter { it.isActive }.size + activePolls = referencePool.values.filter { it.isActive }.size if (orphanedReferences.isNotEmpty() && referencePool.isEmpty()) { log.info { "Last active references removed from pull pool, " } } - if (eventGroup.isNotEmpty()) { - log.info { "Active polls $activePolls/${referencePool.values.size}" } - } else { + if (eventGroup.isEmpty()) { return }