Skip to content

Commit

Permalink
Use one transaction for inserting status and results. (#80)
Browse files Browse the repository at this point in the history
  • Loading branch information
antoinebhs authored Sep 28, 2023
1 parent 16b216a commit b89b054
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public SecurityAnalysisResult find(UUID resultUuid, Set<LimitViolationType> limi
}

@Transactional
public void insert(UUID resultUuid, SecurityAnalysisResult result) {
public void insert(UUID resultUuid, SecurityAnalysisResult result, SecurityAnalysisStatus status) {
Objects.requireNonNull(resultUuid);
Objects.requireNonNull(result);

Expand All @@ -169,6 +169,7 @@ public void insert(UUID resultUuid, SecurityAnalysisResult result) {
);
computationStatusRepository.save(toEntity(resultUuid, null, result.getPreContingencyResult().getStatus().name()));
limitViolationRepository.saveAll(toEntity(resultUuid, null, result.getPreContingencyResult().getLimitViolationsResult().getLimitViolations()));
globalStatusRepository.save(toEntity(resultUuid, status));
}

public void insertStatus(List<UUID> resultUuids, SecurityAnalysisStatus status) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,9 +258,9 @@ public Consumer<Message<String>> consumeRun() {
.flatMap(result -> {
long nanoTime = System.nanoTime();
LOGGER.info("Just run in {}s", TimeUnit.NANOSECONDS.toSeconds(nanoTime - startTime.getAndSet(nanoTime)));
return Mono.fromRunnable(() -> resultRepository.insert(resultContext.getResultUuid(), result))
.then(Mono.fromRunnable(() -> resultRepository.insertStatus(List.of(resultContext.getResultUuid()),
result.getPreContingencyResult().getStatus() == LoadFlowResult.ComponentResult.Status.CONVERGED ? SecurityAnalysisStatus.CONVERGED : SecurityAnalysisStatus.DIVERGED)))
return Mono.fromRunnable(() -> resultRepository.insert(resultContext.getResultUuid(),
result,
result.getPreContingencyResult().getStatus() == LoadFlowResult.ComponentResult.Status.CONVERGED ? SecurityAnalysisStatus.CONVERGED : SecurityAnalysisStatus.DIVERGED))
.then(Mono.just(result))
.doFinally(ignored -> {
long finalNanoTime = System.nanoTime();
Expand Down

0 comments on commit b89b054

Please sign in to comment.