Reduced logging and replaced with controller

This commit is contained in:
bskjon 2024-08-18 20:18:15 +02:00
parent 880285e238
commit 27f45ded91
2 changed files with 25 additions and 5 deletions

View File

@ -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}"
}
}

View File

@ -45,21 +45,23 @@ abstract class EventCoordinator<T : EventImpl, E : EventsManagerImpl<T>> {
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<List<T>>) {
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
}