-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #605 from bcgov/feature/GRAD2-2430
GRAD2-2430: task is completed.
- Loading branch information
Showing
5 changed files
with
58 additions
and
0 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
40 changes: 40 additions & 0 deletions
40
api/src/main/java/ca/bc/gov/educ/api/gradstudent/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,40 @@ | ||
package ca.bc.gov.educ.api.gradstudent.scheduler; | ||
|
||
import ca.bc.gov.educ.api.gradstudent.repository.GradStatusEventRepository; | ||
import ca.bc.gov.educ.api.gradstudent.util.EducGradStudentApiConstants; | ||
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 GradStatusEventRepository gradStatusEventRepository; | ||
private final EducGradStudentApiConstants constants; | ||
|
||
public PurgeOldRecordsScheduler(final GradStatusEventRepository gradStatusEventRepository, | ||
final EducGradStudentApiConstants constants) { | ||
this.gradStatusEventRepository = gradStatusEventRepository; | ||
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.gradStatusEventRepository.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