Skip to content

Commit

Permalink
feat: avoid computation failure if an error occurs in post run treatment
Browse files Browse the repository at this point in the history
Signed-off-by: Joris Mancini <joris.mancini_externe@rte-france.com>
  • Loading branch information
TheMaskedTurtle committed Dec 5, 2024
1 parent 94d02b5 commit dbd0bcd
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,13 @@ protected R run(C runContext, UUID resultUuid, AtomicReference<ReportNode> rootR
preRun(runContext);
CompletableFuture<R> future = runAsync(runContext, provider, resultUuid);
R result = future == null ? null : observer.observeRun("run", runContext, future::get);
postRun(runContext, rootReporter, result);
try {
postRun(runContext, rootReporter, result);
} catch (Exception e) {
// As the exception occurs after a successful run of the computation we don't want the whole computation to fail
// Then we just log the error
LOGGER.error("An error occurred after computation run", e);
}
return result;
}

Expand All @@ -236,7 +242,11 @@ protected R run(C runContext, UUID resultUuid, AtomicReference<ReportNode> rootR
*/
protected void postRun(C runContext, AtomicReference<ReportNode> rootReportNode, R ignoredResult) {
if (runContext.getReportInfos().reportUuid() != null) {
observer.observe("report.send", runContext, () -> reportService.sendReport(runContext.getReportInfos().reportUuid(), rootReportNode.get()));
try {
observer.observe("report.send", runContext, () -> reportService.sendReport(runContext.getReportInfos().reportUuid(), rootReportNode.get()));
} catch (Exception e) {
throw new PostRunException("An error occurred while sending reports", e);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.powsybl.ws.commons.computation.service;

public class PostRunException extends RuntimeException {
public PostRunException(String message, Throwable cause) {
super(message, cause);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,13 @@ public void sendReport(UUID reportUuid, ReportNode reportNode) {
var headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);

String str;
try {
String str = objectMapper.writeValueAsString(reportNode);
restTemplate.exchange(getReportServerURI() + path, HttpMethod.PUT, new HttpEntity<>(str, headers), ReportNode.class);
str = objectMapper.writeValueAsString(reportNode);
} catch (JsonProcessingException error) {
throw new PowsyblException("Error sending report", error);
throw new PowsyblException("Impossible to serialize ReportNode", error);
}
restTemplate.exchange(getReportServerURI() + path, HttpMethod.PUT, new HttpEntity<>(str, headers), ReportNode.class);
}

public void deleteReport(UUID reportUuid) {
Expand Down

0 comments on commit dbd0bcd

Please sign in to comment.