From 158aed7df167197697d700b294d3f04591cc1530 Mon Sep 17 00:00:00 2001 From: Chris Ditcher Date: Thu, 21 Mar 2024 08:33:45 -0700 Subject: [PATCH] Grad2 2540 (#630) * Added scheduler to update RECALCULATE_PROJECTED_GRAD for students with selected criteria * Modified query as per Kim * Fixed unit tests --------- Co-authored-by: chris.ditcher --- .../GraduationStudentRecordRepository.java | 4 +++ .../RefreshNonGradStatusScheduler.java | 32 +++++++++++++++++++ api/src/main/resources/application.yaml | 6 ++-- api/src/test/resources/application.yaml | 2 ++ tools/config/override-configmap-dev.sh | 1 + tools/config/update-configmap.sh | 1 + 6 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 api/src/main/java/ca/bc/gov/educ/api/gradstudent/scheduler/RefreshNonGradStatusScheduler.java diff --git a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/repository/GraduationStudentRecordRepository.java b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/repository/GraduationStudentRecordRepository.java index 9e84a7d2..4cc26667 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/repository/GraduationStudentRecordRepository.java +++ b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/repository/GraduationStudentRecordRepository.java @@ -87,4 +87,8 @@ void updateStudentGuidPenXrefRecord( @Modifying @Query("update GraduationStudentRecordEntity e set e.recalculateGradStatus = :recalculateGradStatus where e.studentID = :studentGuid") void updateGradStudentRecalculationRecalculateGradStatusFlag(@Param(value = "studentGuid") UUID studentGuid, @Param(value = "recalculateGradStatus") String recalculateGradStatus); + + @Modifying + @Query( "update GraduationStudentRecordEntity e set e.recalculateProjectedGrad = 'Y' where e.studentStatus = 'CUR' and e.programCompletionDate is null and (e.studentGrade = '12' or e.studentGrade = 'AD')") + void updateGradStudentRecalcFlagsForCurrentStudentsWithNullCompletion(); } diff --git a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/scheduler/RefreshNonGradStatusScheduler.java b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/scheduler/RefreshNonGradStatusScheduler.java new file mode 100644 index 00000000..e48c61d6 --- /dev/null +++ b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/scheduler/RefreshNonGradStatusScheduler.java @@ -0,0 +1,32 @@ +package ca.bc.gov.educ.api.gradstudent.scheduler; + +import ca.bc.gov.educ.api.gradstudent.repository.GraduationStudentRecordRepository; +import jakarta.transaction.Transactional; +import lombok.extern.slf4j.Slf4j; +import net.javacrumbs.shedlock.core.LockAssert; +import net.javacrumbs.shedlock.spring.annotation.SchedulerLock; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Component; + +@Component +@Slf4j +public class RefreshNonGradStatusScheduler { + private final GraduationStudentRecordRepository graduationStudentRecordRepository; + + @Autowired + public RefreshNonGradStatusScheduler(GraduationStudentRecordRepository graduationStudentRecordRepository) { + this.graduationStudentRecordRepository = graduationStudentRecordRepository; + } + + @Scheduled(cron = "${cron.scheduled.process.refresh-non-grad-status.run}") + @SchedulerLock(name = "refreshNonGradStatusLock", + lockAtLeastFor = "PT2M", lockAtMostFor = "PT5M") + @Transactional + public void refreshNonGradStatuses() { + LockAssert.assertLocked(); + graduationStudentRecordRepository.updateGradStudentRecalcFlagsForCurrentStudentsWithNullCompletion(); + } + + +} diff --git a/api/src/main/resources/application.yaml b/api/src/main/resources/application.yaml index 7276e085..e577306e 100644 --- a/api/src/main/resources/application.yaml +++ b/api/src/main/resources/application.yaml @@ -79,8 +79,8 @@ server: worker: 128 io: 16 #port: ${HTTP_PORT} - tomcat: - connection-timeout: 200s + #tomcat: + #connection-timeout: 200s #API Documentation springdoc: @@ -109,6 +109,8 @@ cron: purge-old-records: run: ${CRON_SCHEDULED_PURGE_OLD_RECORDS} staleInDays: ${RECORDS_STALE_IN_DAYS} + refresh-non-grad-status: + run: ${CRON_SCHEDULED_REFRESH_NON_GRAD_STATUS} #Resilience resilience4j.retry: diff --git a/api/src/test/resources/application.yaml b/api/src/test/resources/application.yaml index 85f9516f..de36ae5a 100644 --- a/api/src/test/resources/application.yaml +++ b/api/src/test/resources/application.yaml @@ -98,6 +98,8 @@ cron: purge-old-records: run: 0 30 0 * * * staleInDays: 90 + refresh-non-grad-status: + run: 0 30 0 * * * #Endpoint properties endpoint: diff --git a/tools/config/override-configmap-dev.sh b/tools/config/override-configmap-dev.sh index fc07044d..8e9fd6c4 100644 --- a/tools/config/override-configmap-dev.sh +++ b/tools/config/override-configmap-dev.sh @@ -44,4 +44,5 @@ echo Creating config map "$APP_NAME"-flb-sc-config-map oc create -n "$GRAD_NAMESPACE"-"$envValue" configmap "$APP_NAME"-flb-sc-config-map \ --from-literal=fluent-bit.conf="$FLB_CONFIG" \ --from-literal=parsers.conf="$PARSER_CONFIG" \ + --from-literal=CRON_SCHEDULED_REFRESH_NON_GRAD_STATUS="0 */10 * ? * *" --dry-run=client -o yaml | oc apply -f - diff --git a/tools/config/update-configmap.sh b/tools/config/update-configmap.sh index 8206fd0c..8f28d778 100644 --- a/tools/config/update-configmap.sh +++ b/tools/config/update-configmap.sh @@ -65,6 +65,7 @@ oc create -n "$GRAD_NAMESPACE"-"$envValue" configmap "$APP_NAME"-config-map \ --from-literal=MAXIMUM_POOL_SIZE="20" \ --from-literal=MAX_RETRY_ATTEMPTS="3" \ --from-literal=PEN_API="http://student-api-master.$COMMON_NAMESPACE-$envValue.svc.cluster.local:8080/" \ + --from-literal=CRON_SCHEDULED_REFRESH_NON_GRAD_STATUS="0 0 0 1 * ?" \ --dry-run=client -o yaml | oc apply -f - echo Creating config map "$APP_NAME"-flb-sc-config-map