Skip to content

Commit

Permalink
fix: prevent duplicate events for drgs and decisions
Browse files Browse the repository at this point in the history
When writing the records after deploying a new DRG we would iterate over all the drgs and decisions in the DeploymentRecord. New drgs and decisions get gradually appended to the DeploymentRecord for each resource that's being processed. Since we iterate over this for every resource, it causes the same event to be send multiple times. Once for each of the drgs deployed.

By filtering the drg metadata that is available in the DeploymentRecord to only include the resource that we are currently transforming we can stop this behavior and support deploying multiple drgs at once.

(cherry picked from commit 223d5c7)
  • Loading branch information
remcowesterhoud authored and github-actions[bot] committed May 30, 2022
1 parent fbe4d57 commit 9c5e430
Showing 1 changed file with 12 additions and 2 deletions.
Expand Up @@ -235,8 +235,12 @@ private boolean isDuplicate(
}

private void writeRecords(final DeploymentRecord deployment, final DeploymentResource resource) {
final var metadataRecords =
deployment.decisionRequirementsMetadata().stream()
.filter(metadata -> metadata.getResourceName().equals(resource.getResourceName()))
.collect(Collectors.toList());

for (final DecisionRequirementsMetadataRecord drg : deployment.decisionRequirementsMetadata()) {
for (final DecisionRequirementsMetadataRecord drg : metadataRecords) {
if (!drg.isDuplicate()) {
stateWriter.appendFollowUpEvent(
drg.getDecisionRequirementsKey(),
Expand All @@ -253,8 +257,14 @@ private void writeRecords(final DeploymentRecord deployment, final DeploymentRes
}
}

final var decisionRequirementKeys =
metadataRecords.stream()
.map(DecisionRequirementsMetadataRecord::getDecisionRequirementsKey)
.collect(Collectors.toList());

for (final DecisionRecord decision : deployment.decisionsMetadata()) {
if (!decision.isDuplicate()) {
if (!decision.isDuplicate()
&& decisionRequirementKeys.contains(decision.getDecisionRequirementsKey())) {
stateWriter.appendFollowUpEvent(
decision.getDecisionKey(),
DecisionIntent.CREATED,
Expand Down

0 comments on commit 9c5e430

Please sign in to comment.