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