From 24ae1c9b6d78bfd19b021c1479a6f129fd41a3d8 Mon Sep 17 00:00:00 2001 From: SoLetsDev <74216496+SoLetsDev@users.noreply.github.com> Date: Tue, 28 Nov 2023 09:33:38 -0800 Subject: [PATCH] adding additional logging to updateAttachedSagaWithEvents to determine why saga information isn't being saved sometimes. --- .../educ/penreg/api/service/SagaService.java | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/api/src/main/java/ca/bc/gov/educ/penreg/api/service/SagaService.java b/api/src/main/java/ca/bc/gov/educ/penreg/api/service/SagaService.java index dcc6d99d..ef723c7b 100644 --- a/api/src/main/java/ca/bc/gov/educ/penreg/api/service/SagaService.java +++ b/api/src/main/java/ca/bc/gov/educ/penreg/api/service/SagaService.java @@ -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; @@ -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); } }