Listener candidates
This commit is contained in:
1 parent
603725a1ce
commit
a65a159e35
1 file changed
+30
-7
@@ -68,21 +68,38 @@ abstract class TaskPollerImplementation(
|
||||
val results = mutableListOf<PollResult>()
|
||||
|
||||
for (task in tasks) {
|
||||
val listener = TaskListenerRegistry.getListeners()
|
||||
.firstOrNull { it.supports(task) && !it.isBusy } ?: continue
|
||||
|
||||
val candidates = TaskListenerRegistry.getListeners()
|
||||
.filter { it.supports(task) && !it.isBusy }
|
||||
|
||||
if (candidates.isEmpty()) {
|
||||
results += PollResult(
|
||||
taskId = task.taskId.toString(),
|
||||
type = task::class.simpleName.toString(),
|
||||
statusPlain = "[IGNORED]",
|
||||
statusColored = colorize("[IGNORED]", Color.YELLOW),
|
||||
listener = "NO_MATCHING_LISTENER"
|
||||
)
|
||||
continue
|
||||
}
|
||||
|
||||
var accepted = false
|
||||
|
||||
for (listener in candidates) {
|
||||
val reporter = reporterFactory(task)
|
||||
val accepted = try {
|
||||
|
||||
val ok = try {
|
||||
listener.accept(task, reporter)
|
||||
} catch (e: Exception) {
|
||||
log.error(e) { "Error while processing task ${task.taskId} by listener ${listener.getWorkerId()}" }
|
||||
log.error(e) {
|
||||
"Error while processing task ${task.taskId} by listener ${listener.getWorkerId()}"
|
||||
}
|
||||
false
|
||||
}
|
||||
|
||||
// Plain status (used for alignment) and colored status (used for display)
|
||||
val (statusPlain, statusColored) = when {
|
||||
accepted -> Pair("[ACCEPTED]", colorize("[ACCEPTED]", Color.GREEN))
|
||||
else -> Pair("[IGNORED]", colorize("[IGNORED]", Color.YELLOW))
|
||||
ok -> "[ACCEPTED]" to colorize("[ACCEPTED]", Color.GREEN)
|
||||
else -> "[IGNORED]" to colorize("[IGNORED]", Color.YELLOW)
|
||||
}
|
||||
|
||||
results += PollResult(
|
||||
@@ -93,6 +110,12 @@ abstract class TaskPollerImplementation(
|
||||
listener = listener.getWorkerId()
|
||||
)
|
||||
|
||||
if (ok) {
|
||||
accepted = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
acceptedAny = acceptedAny || accepted
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user