Skip to content

Commit

Permalink
adding additional logging to updateAttachedSagaWithEvents to determin…
Browse files Browse the repository at this point in the history
…e why saga information isn't being saved sometimes.
  • Loading branch information
SoLetsDev committed Nov 28, 2023
1 parent 3a343c1 commit 24ae1c9
Showing 1 changed file with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package ca.bc.gov.educ.penreg.api.service;

import ca.bc.gov.educ.penreg.api.model.v1.PenRequestBatchMultipleLocalID;
import ca.bc.gov.educ.penreg.api.model.v1.PenRequestBatchMultiplePen;
import ca.bc.gov.educ.penreg.api.model.v1.Saga;
import ca.bc.gov.educ.penreg.api.model.v1.SagaEvent;
Expand Down Expand Up @@ -93,12 +92,17 @@ public Saga createSagaRecord(final Saga saga) {
@Retryable(value = {Exception.class}, maxAttempts = 5, backoff = @Backoff(multiplier = 2, delay = 2000))
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void updateAttachedSagaWithEvents(final Saga saga, final SagaEvent sagaEvent) {
saga.setUpdateDate(LocalDateTime.now());
this.getSagaRepository().save(saga);
val result = this.getSagaEventRepository()
.findBySagaAndSagaEventOutcomeAndSagaEventStateAndSagaStepNumber(saga, sagaEvent.getSagaEventOutcome(), sagaEvent.getSagaEventState(), sagaEvent.getSagaStepNumber() - 1); //check if the previous step was same and had same outcome, and it is due to replay.
if (result.isEmpty()) {
this.getSagaEventRepository().save(sagaEvent);
try {
saga.setUpdateDate(LocalDateTime.now());
this.getSagaRepository().save(saga);
val result = this.getSagaEventRepository()
.findBySagaAndSagaEventOutcomeAndSagaEventStateAndSagaStepNumber(saga, sagaEvent.getSagaEventOutcome(), sagaEvent.getSagaEventState(), sagaEvent.getSagaStepNumber() - 1); //check if the previous step was same and had same outcome, and it is due to replay.
if (result.isEmpty()) {
this.getSagaEventRepository().save(sagaEvent);
}
} catch (Exception e) {
log.error("updateAttachedSagaWithEvents failed for PenRequestBatchId :: {}, SagaId :: {}, SagaEventState :: {}, Error :: {}", saga.getPenRequestBatchID(), saga.getSagaId(), sagaEvent.getSagaEventState(), e.toString());
throw new RuntimeException(e);
}
}

Expand Down

0 comments on commit 24ae1c9

Please sign in to comment.