Skip to content

Commit 3974807

Browse files
authored
Merge pull request #113 from bcgov/feature/replicate-student-courses-saga
saga fix to limit number of sagas being run, and add missed file
2 parents 3675345 + fc8cb40 commit 3974807

3 files changed

Lines changed: 3 additions & 12 deletions

File tree

api/src/main/java/ca/bc/gov/educ/api/pen/replication/repository/SagaRepository.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public interface SagaRepository extends JpaRepository<Saga, UUID>, JpaSpecificat
2424
* @return the list
2525
*/
2626
List<Saga> findAllByStatusInOrderByCreateDate(List<String> statuses);
27-
27+
List<Saga> findTop500ByStatusInOrderByCreateDate(List<String> statuses);
2828

2929
/**
3030
* Find all by create date before list.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public EventTaskScheduler(final SagaRepository sagaRepository, final SagaService
5858
@Scheduled(cron = "${cron.scheduled.process.uncompleted.saga}")
5959
@SchedulerLock(name = "REPLAY_UNCOMPLETED_SAGAS", lockAtLeastFor = "${cron.scheduled.process.uncompleted.saga.lockAtLeastFor}", lockAtMostFor = "${cron.scheduled.process.uncompleted.saga.lockAtMostFor}")
6060
public void findAndProcessUncompletedSagas() {
61-
final List<Saga> sagas = this.getSagaRepository().findAllByStatusInOrderByCreateDate(this.getStatusFilters());
61+
final List<Saga> sagas = this.getSagaRepository().findTop500ByStatusInOrderByCreateDate(this.getStatusFilters());
6262
if (!sagas.isEmpty()) {
6363
this.processUncompletedSagas(sagas);
6464
}

api/src/main/java/ca/bc/gov/educ/api/pen/replication/service/TraxStudentCourseService.java

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
import ca.bc.gov.educ.api.pen.replication.model.TraxStudentCourseEntity;
44
import ca.bc.gov.educ.api.pen.replication.repository.TraxStudentCourseRepository;
5-
import jakarta.persistence.EntityManager;
6-
import jakarta.persistence.PersistenceContext;
75
import lombok.extern.slf4j.Slf4j;
86
import org.springframework.stereotype.Service;
97
import org.springframework.transaction.annotation.Propagation;
@@ -16,9 +14,6 @@
1614
public class TraxStudentCourseService {
1715
private final TraxStudentCourseRepository traxStudentCourseRepository;
1816

19-
@PersistenceContext
20-
private EntityManager entityManager;
21-
2217
public TraxStudentCourseService(TraxStudentCourseRepository traxStudentCourseRepository) {
2318
this.traxStudentCourseRepository = traxStudentCourseRepository;
2419
}
@@ -49,11 +44,7 @@ public void saveTraxStudentCourses(final List<TraxStudentCourseEntity> studentCo
4944
log.debug("Saving new course list for PEN: {}, count: {}",
5045
studentCourseEntityList.get(0).getStudXcrseId().getStudNo(),
5146
studentCourseEntityList.size());
52-
entityManager.clear();
53-
for (TraxStudentCourseEntity entity : studentCourseEntityList) {
54-
entityManager.persist(entity);
55-
}
56-
entityManager.flush();
47+
traxStudentCourseRepository.saveAllAndFlush(studentCourseEntityList);
5748
log.debug("Saved new trax student courses to the database, count: {}", studentCourseEntityList.size());
5849
}
5950
} catch (Exception e) {

0 commit comments

Comments
 (0)