Skip to content

Commit

Permalink
fix: wait for all competable futures to finish before moving over
Browse files Browse the repository at this point in the history
Added error handling as well.
  • Loading branch information
goldmann committed Sep 20, 2024
1 parent ea086e3 commit dbe339a
Showing 1 changed file with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import java.util.stream.Stream;

import org.cyclonedx.model.Bom;
import org.jboss.sbomer.core.errors.ApplicationException;
import org.jboss.sbomer.core.features.sbom.enums.GenerationResult;
import org.jboss.sbomer.core.features.sbom.utils.MDCUtils;
import org.jboss.sbomer.core.features.sbom.utils.SbomUtils;
Expand Down Expand Up @@ -354,26 +355,38 @@ protected UpdateControl<GenerationRequest> reconcileFinished(
log.debug("Reconcile FINISHED for '{}'...", generationRequest.getName());

// Store files in S3
CompletableFuture.runAsync(() -> s3LogHandler.storeFiles(generationRequest));
CompletableFuture<Void> storeLogs = CompletableFuture.runAsync(() -> s3LogHandler.storeFiles(generationRequest))
.exceptionally((e) -> {
// This is not fatal
log.warn("Storing files in S3 failed", e);
return null;
});

List<Sbom> sboms = sbomRepository.findSbomsByGenerationRequest(generationRequest.getId());

CompletableFuture.runAsync(() -> {
CompletableFuture<Void> publishToUmb = CompletableFuture.runAsync(() -> {
try {
notificationService.notifyCompleted(sboms);
} catch (FeatureDisabledException e) {
log.warn(e.getMessage(), e);
}
}).exceptionally((e) -> {
throw new ApplicationException("UMB notification failed", e);
});

CompletableFuture.runAsync(() -> {
CompletableFuture<Void> uploadToAtlas = CompletableFuture.runAsync(() -> {
try {
atlasHandler.upload(sboms);
} catch (FeatureDisabledException e) {
log.warn(e.getMessage(), e);
}
}).exceptionally((e) -> {
throw new ApplicationException("Uploading manifests to Atlas failed", e);
});

// Wait for all tasks to be done
CompletableFuture.allOf(storeLogs, publishToUmb, uploadToAtlas).join();

// At this point al the work is finished and we can clean up the GenerationRequest Kubernetes resource.
cleanupFinishedGenerationRequest(generationRequest);

Expand Down

0 comments on commit dbe339a

Please sign in to comment.