-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GRAD2-2430: task is complete.
- Loading branch information
Showing
6 changed files
with
61 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
api/src/main/java/ca/bc/gov/educ/api/dataconversion/scheduler/PurgeOldRecordsScheduler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package ca.bc.gov.educ.api.dataconversion.scheduler; | ||
|
||
import ca.bc.gov.educ.api.dataconversion.repository.EventRepository; | ||
import ca.bc.gov.educ.api.dataconversion.util.EducGradDataConversionApiConstants; | ||
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 EducGradDataConversionApiConstants constants; | ||
|
||
public PurgeOldRecordsScheduler(final EventRepository eventRepository, | ||
final EducGradDataConversionApiConstants constants) { | ||
this.eventRepository = eventRepository; | ||
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); | ||
} | ||
|
||
|
||
private LocalDateTime calculateCreateDateBasedOnStaleEventInDays() { | ||
final LocalDateTime currentTime = LocalDateTime.now(); | ||
return currentTime.minusDays(this.constants.getRecordsStaleInDays()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters