Fixed Exam update task to not brake on single exam update error

This commit is contained in:
anhefti 2021-09-08 16:02:58 +02:00
parent 291a0e3532
commit c3eda2b81d
3 changed files with 12 additions and 15 deletions

View file

@ -390,7 +390,7 @@ public class ExamForm implements TemplateComposer {
.withExec(this.examCreateClientConfigPopup.exportFunction(
exam.institutionId,
exam.getName()))
.publishIf(() -> modifyGrant && readonly)
.publishIf(() -> editable && readonly)
.newAction(ActionDefinition.EXAM_MODIFY_SEB_RESTRICTION_DETAILS)
.withEntityKey(entityKey)
@ -416,13 +416,13 @@ public class ExamForm implements TemplateComposer {
.withEntityKey(entityKey)
.withExec(this.examProctoringSettings.settingsFunction(this.pageService, modifyGrant))
.noEventPropagation()
.publishIf(() -> proctoringEnabled && readonly)
.publishIf(() -> editable && proctoringEnabled && readonly)
.newAction(ActionDefinition.EXAM_PROCTORING_OFF)
.withEntityKey(entityKey)
.withExec(this.examProctoringSettings.settingsFunction(this.pageService, modifyGrant))
.noEventPropagation()
.publishIf(() -> !proctoringEnabled && readonly)
.publishIf(() -> editable && !proctoringEnabled && readonly)
.newAction(ActionDefinition.EXAM_DELETE)
.withEntityKey(entityKey)

View file

@ -133,7 +133,7 @@ class ExamSessionControlTask implements DisposableBean {
.getOrThrow()
.stream()
.filter(exam -> exam.startTime.minus(this.examTimePrefix).isBefore(now))
.map(exam -> this.examUpdateHandler.setRunning(exam, updateId))
.flatMap(exam -> Result.skipOnError(this.examUpdateHandler.setRunning(exam, updateId)))
.collect(Collectors.toMap(Exam::getId, Exam::getName));
if (!updated.isEmpty()) {
@ -158,10 +158,8 @@ class ExamSessionControlTask implements DisposableBean {
.getOrThrow()
.stream()
.filter(exam -> exam.endTime != null && exam.endTime.plus(this.examTimeSuffix).isBefore(now))
.map(exam -> this.examUpdateHandler.setFinished(exam, updateId))
.map(this.examProcotringRoomService::disposeRoomsForExam)
.filter(result -> !result.hasError())
.map(Result::get)
.flatMap(exam -> Result.skipOnError(this.examUpdateHandler.setFinished(exam, updateId)))
.flatMap(exam -> Result.skipOnError(this.examProcotringRoomService.disposeRoomsForExam(exam)))
.collect(Collectors.toMap(Exam::getId, Exam::getName));
if (!updated.isEmpty()) {

View file

@ -64,14 +64,15 @@ class ExamUpdateHandler {
final DateTime now = DateTime.now(DateTimeZone.UTC);
if (exam.getStatus() == ExamStatus.UP_COMING
&& exam.endTime.plus(this.examTimeSuffix).isBefore(now)) {
return setRunning(exam, this.createUpdateId());
return setRunning(exam, this.createUpdateId())
.getOr(exam);
} else {
return exam;
}
});
}
Exam setRunning(final Exam exam, final String updateId) {
Result<Exam> setRunning(final Exam exam, final String updateId) {
if (log.isDebugEnabled()) {
log.debug("Update exam as running: {}", exam);
}
@ -85,11 +86,10 @@ class ExamUpdateHandler {
.flatMap(this.sebRestrictionService::applySEBClientRestriction)
.flatMap(e -> this.examDAO.releaseLock(e.id, updateId))
.onError(error -> this.examDAO.forceUnlock(exam.id)
.onError(unlockError -> log.error("Failed to force unlock update look for exam: {}", exam.id)))
.getOrThrow();
.onError(unlockError -> log.error("Failed to force unlock update look for exam: {}", exam.id)));
}
Exam setFinished(final Exam exam, final String updateId) {
Result<Exam> setFinished(final Exam exam, final String updateId) {
if (log.isDebugEnabled()) {
log.debug("Update exam as finished: {}", exam);
}
@ -102,8 +102,7 @@ class ExamUpdateHandler {
updateId))
.flatMap(this.sebRestrictionService::releaseSEBClientRestriction)
.flatMap(e -> this.examDAO.releaseLock(e.id, updateId))
.onError(error -> this.examDAO.forceUnlock(exam.id))
.getOrThrow();
.onError(error -> this.examDAO.forceUnlock(exam.id));
}
}