Skip to content

Commit 151644b

Browse files
committed
Fix for course replication saga not picking up queued sagas
1 parent fc8cb40 commit 151644b

2 files changed

Lines changed: 5 additions & 3 deletions

File tree

api/src/main/java/ca/bc/gov/educ/api/pen/replication/orchestrator/StudentCourseUpdateOrchestrator.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
import static ca.bc.gov.educ.api.pen.replication.constants.EventOutcome.*;
3232
import static ca.bc.gov.educ.api.pen.replication.constants.EventType.*;
33+
import static ca.bc.gov.educ.api.pen.replication.constants.SagaStatusEnum.IN_PROGRESS;
3334

3435
@Component
3536
@Slf4j
@@ -65,6 +66,7 @@ public void populateStepsToExecuteMap() {
6566

6667
private void prepareStudentCourseUpdate(final Event event, final Saga saga, final StudentCourseUpdateSagaData sagaData) {
6768
saga.setSagaState(PREPARE_STUDENT_COURSE_UPDATE.toString());
69+
saga.setStatus(IN_PROGRESS.toString());
6870
final SagaEvent eventStates = this.createEventState(saga, event.getEventType(), event.getEventOutcome(), event.getEventPayload());
6971
this.getSagaService().updateAttachedSagaWithEvents(saga, eventStates);
7072

api/src/main/java/ca/bc/gov/educ/api/pen/replication/schedulers/EventTaskScheduler.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,10 @@ private void processQueuedSaga(final Saga saga) {
9999
if (sagaData != null) {
100100
val studentID = sagaData.getStudentID();
101101

102-
// Check if there's a conflicting in-progress saga for this student
103-
val conflictingSagas = this.getSagaService().findInProgressStudentCourseUpdateSagasByStudentID(studentID).stream().filter(s -> !s.getSagaId().equals(saga.getSagaId())).toList();
102+
// If this saga isn't the oldest for this student, don't run it
103+
val inProgressSagas = this.getSagaService().findInProgressStudentCourseUpdateSagasByStudentID(studentID);
104104

105-
if (conflictingSagas.isEmpty()) {
105+
if (inProgressSagas.isEmpty() || inProgressSagas.get(0).getSagaId().equals(saga.getSagaId())) {
106106
this.getSagaEnumOrchestratorMap().get(SagaEnum.getKeyFromValue(saga.getSagaName())).startSaga(saga);
107107
log.info("Started queued saga {} for studentID {}", saga.getSagaId(), studentID);
108108
}

0 commit comments

Comments
 (0)