Fix group precondition not respecting priority

This commit is contained in:
reusedname 2025-02-25 23:21:43 +05:00
parent c6389b9481
commit dedb97166b
1 changed files with 10 additions and 5 deletions

View File

@ -175,22 +175,27 @@ public class RecordingPreconditions {
return;
}
for (String modelUrl : modelGroup.get().getModelUrls()) {
if (modelUrl.equals(model.getUrl())) {
for (var groupModel : modelGroup.get().getModelUrls().stream()
.map(modelUrl -> getModelForUrl(modelUrl))
.filter(x -> x.isPresent())
.map(x -> x.get())
.sorted((l, r) -> Integer.compare(r.getPriority(), l.getPriority())) // high to low
.toList()) {
if (model.getUrl().equals(groupModel.getUrl())) {
// no other model with higher prio is online, start recording
// but before that stop all recordings of models with lower prio
stopModelsWithLowerPrio(modelGroup.get());
return;
} else {
Optional<Model> otherModel = getModelForUrl(modelUrl);
Optional<Model> otherModel = getModelForUrl(groupModel.getUrl());
if (otherModel.isPresent()) {
if (otherModelIsRecorded(otherModel.get())) {
if (!otherModel.get().isSuspended() && otherModelIsRecorded(otherModel.get())) {
throw new PreconditionNotMetException(otherModel.get() + " from the same group is already recorded");
} else if (otherModelCanBeRecorded(otherModel.get())) {
throw new PreconditionNotMetException(otherModel.get() + " from the same group can be recorded");
}
} else {
LOG.warn("Couldn't check if model from same group has higer prio for {}", modelUrl);
LOG.warn("Couldn't check if model from same group has higer prio for {}", groupModel.getUrl());
}
}
}