Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Grad release 1.12.0 #298

Merged
merged 3 commits into from
Jan 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>ca.bc.gov.educ</groupId>
<artifactId>educ-grad-trax-api</artifactId>
<version>1.8.47</version>
<version>1.8.48</version>
<name>educ-grad-trax-api</name>
<description>Ministry of Education GRAD TRAX API</description>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@

import ca.bc.gov.educ.api.trax.model.entity.Event;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
Expand All @@ -15,4 +19,9 @@ public interface EventRepository extends JpaRepository<Event, UUID> {

List<Event> findAllByEventStatusOrderByCreateDate(String eventStatus);

@Transactional
@Modifying
@Query("delete from Event where createDate <= :createDate")
void deleteByCreateDateBefore(LocalDateTime createDate);

}
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package ca.bc.gov.educ.api.trax.repository;

import ca.bc.gov.educ.api.trax.model.entity.TraxUpdatedPubEvent;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Slice;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
Expand Down Expand Up @@ -38,4 +40,9 @@ public interface TraxUpdatedPubEventRepository extends JpaRepository<TraxUpdated
*/
List<TraxUpdatedPubEvent> findByEventStatusOrderByCreateDate(String eventStatus);

@Transactional
@Modifying
@Query("delete from TraxUpdatedPubEvent where createDate <= :createDate")
void deleteByCreateDateBefore(LocalDateTime createDate);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package ca.bc.gov.educ.api.trax.scheduler;

import ca.bc.gov.educ.api.trax.repository.EventRepository;
import ca.bc.gov.educ.api.trax.repository.TraxUpdatedPubEventRepository;
import ca.bc.gov.educ.api.trax.util.EducGradTraxApiConstants;
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.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

@Component
@Slf4j
public class PurgeOldRecordsScheduler {

private final EventRepository eventRepository;
private final TraxUpdatedPubEventRepository traxUpdatedPubEventRepository;
private final EducGradTraxApiConstants constants;

public PurgeOldRecordsScheduler(final EventRepository eventRepository,
final TraxUpdatedPubEventRepository traxUpdatedPubEventRepository,
final EducGradTraxApiConstants constants) {
this.eventRepository = eventRepository;
this.traxUpdatedPubEventRepository = traxUpdatedPubEventRepository;
this.constants = constants;
}

@Scheduled(cron = "${cron.scheduled.process.purge-old-records.run}")
@SchedulerLock(name = "PurgeOldRecordsLock",
lockAtLeastFor = "PT1H", lockAtMostFor = "PT1H") //midnight job so lock for an hour
@Transactional
public void purgeOldRecords() {
LockAssert.assertLocked();
final LocalDateTime createDateToCompare = this.calculateCreateDateBasedOnStaleEventInDays();
this.eventRepository.deleteByCreateDateBefore(createDateToCompare);
this.traxUpdatedPubEventRepository.deleteByCreateDateBefore(createDateToCompare);
}

private LocalDateTime calculateCreateDateBasedOnStaleEventInDays() {
final LocalDateTime currentTime = LocalDateTime.now();
return currentTime.minusDays(this.constants.getRecordsStaleInDays());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -169,4 +169,7 @@ public class EducGradTraxApiConstants {
@Value("${cron.scheduled.process.trigger-jobs.read-trax-update.threshold}")
private int traxTriggersProcessingThreshold;

@Value("${cron.scheduled.process.purge-old-records.staleInDays}")
private int recordsStaleInDays;

}
3 changes: 3 additions & 0 deletions api/src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@ cron:
lockAtLeastFor: ${CRON_SCHEDULED_TRIGGER_TRAX_UPDATES_LOCK_AT_LEAST_FOR}
lockAtMostFor: ${CRON_SCHEDULED_TRIGGER_TRAX_UPDATES_LOCK_AT_MOST_FOR}
threshold: ${CRON_SCHEDULED_TRIGGER_TRAX_UPDATES_THRESHOLD}
purge-old-records:
run: ${CRON_SCHEDULED_PURGE_OLD_RECORDS}
staleInDays: ${RECORDS_STALE_IN_DAYS}

#Incremental Trax Update
trax:
Expand Down
3 changes: 3 additions & 0 deletions api/src/test/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ cron:
lockAtLeastFor: 800ms
lockAtMostFor: 900ms
threshold: 100
purge-old-records:
run: 0 30 0 * * *
staleInDays: 90

#Incremental Trax Update
trax:
Expand Down
Loading