|
1 | 1 | package ca.bc.gov.educ.api.edx.schedulers;
|
2 | 2 |
|
3 |
| -import ca.bc.gov.educ.api.edx.model.v1.EdxUserDistrictEntity; |
4 |
| -import ca.bc.gov.educ.api.edx.model.v1.EdxUserSchoolEntity; |
5 |
| -import ca.bc.gov.educ.api.edx.repository.*; |
| 3 | +import ca.bc.gov.educ.api.edx.model.v1.EdxUserDistrictLightEntity; |
| 4 | +import ca.bc.gov.educ.api.edx.model.v1.EdxUserSchoolLightEntity; |
| 5 | +import ca.bc.gov.educ.api.edx.repository.EdxUserDistrictLightRepository; |
| 6 | +import ca.bc.gov.educ.api.edx.repository.EdxUserSchoolLightRepository; |
6 | 7 | import lombok.extern.slf4j.Slf4j;
|
7 | 8 | import net.javacrumbs.shedlock.core.LockAssert;
|
8 | 9 | import net.javacrumbs.shedlock.spring.annotation.SchedulerLock;
|
|
17 | 18 | @Component
|
18 | 19 | @Slf4j
|
19 | 20 | public class EdxUserScheduler {
|
20 |
| - private final EdxUserSchoolRepository edxUserSchoolRepository; |
21 |
| - private final EdxUserDistrictRepository edxUserDistrictRepository; |
| 21 | + private final EdxUserSchoolLightRepository edxUserSchoolLightRepository; |
| 22 | + private final EdxUserDistrictLightRepository edxUserDistrictLightRepository; |
22 | 23 |
|
23 |
| - public EdxUserScheduler( |
24 |
| - EdxUserSchoolRepository edxUserSchoolRepository, |
25 |
| - EdxUserDistrictRepository edxUserDistrictRepository |
26 |
| - ) { |
27 |
| - this.edxUserSchoolRepository = edxUserSchoolRepository; |
28 |
| - this.edxUserDistrictRepository = edxUserDistrictRepository; |
29 |
| - } |
| 24 | + public EdxUserScheduler(EdxUserSchoolLightRepository edxUserSchoolLightRepository, EdxUserDistrictLightRepository edxUserDistrictLightRepository) { |
| 25 | + this.edxUserSchoolLightRepository = edxUserSchoolLightRepository; |
| 26 | + this.edxUserDistrictLightRepository = edxUserDistrictLightRepository; |
| 27 | + } |
30 | 28 |
|
31 |
| - @Scheduled(cron = "${scheduled.jobs.purge.edx.users.cron}") |
32 |
| - @SchedulerLock(name = "PurgeEdxUsers", lockAtLeastFor = "PT4H", lockAtMostFor = "PT4H") |
33 |
| - @Transactional(propagation = Propagation.REQUIRES_NEW) |
34 |
| - public void purgeExpiredEdxUsers() { |
35 |
| - LockAssert.assertLocked(); |
| 29 | + @Scheduled(cron = "${scheduled.jobs.purge.edx.users.cron}") |
| 30 | + @SchedulerLock(name = "PurgeEdxUsers", lockAtLeastFor = "PT4H", lockAtMostFor = "PT4H") |
| 31 | + @Transactional(propagation = Propagation.REQUIRES_NEW) |
| 32 | + public void purgeExpiredEdxUsers() { |
| 33 | + LockAssert.assertLocked(); |
36 | 34 |
|
37 |
| - final LocalDateTime now = LocalDateTime.now(); |
38 |
| - List<EdxUserSchoolEntity> expiredSchoolUsers = this.edxUserSchoolRepository.findAllByExpiryDateBefore(now); |
39 |
| - List<EdxUserDistrictEntity> expiredDistrictUsers = this.edxUserDistrictRepository.findAllByExpiryDateBefore(now); |
| 35 | + final LocalDateTime now = LocalDateTime.now(); |
| 36 | + List<EdxUserSchoolLightEntity> expiredSchoolUsers = this.edxUserSchoolLightRepository.findAllByExpiryDateBefore(now); |
| 37 | + List<EdxUserDistrictLightEntity> expiredDistrictUsers = this.edxUserDistrictLightRepository.findAllByExpiryDateBefore(now); |
40 | 38 |
|
41 |
| - log.info("Purging expired school users"); |
42 |
| - expiredSchoolUsers.forEach(edxUserSchoolEntity -> log.info("Removing EDX user " + edxUserSchoolEntity.getEdxUserEntity().getEdxUserID() + " from school ID: " + edxUserSchoolEntity.getSchoolID())); |
43 |
| - this.edxUserSchoolRepository.deleteAll(expiredSchoolUsers); |
44 |
| - log.info("Purging expired district users"); |
45 |
| - expiredDistrictUsers.forEach(edxUserDistrictEntity -> log.info("Removing EDX user " + edxUserDistrictEntity.getEdxUserEntity().getEdxUserID() + " from district ID: " + edxUserDistrictEntity.getDistrictID())); |
46 |
| - this.edxUserDistrictRepository.deleteAll(expiredDistrictUsers); |
47 |
| - } |
| 39 | + log.info("Purging expired school users"); |
| 40 | + expiredSchoolUsers.forEach(edxUserSchoolEntity -> log.info("Removing EDX user " + edxUserSchoolEntity.getEdxUserID() + " from school ID: " + edxUserSchoolEntity.getSchoolID())); |
| 41 | + this.edxUserSchoolLightRepository.deleteAll(expiredSchoolUsers); |
| 42 | + log.info("Purging expired district users"); |
| 43 | + expiredDistrictUsers.forEach(edxUserDistrictEntity -> log.info("Removing EDX user " + edxUserDistrictEntity.getEdxUserID() + " from district ID: " + edxUserDistrictEntity.getDistrictID())); |
| 44 | + this.edxUserDistrictLightRepository.deleteAll(expiredDistrictUsers); |
| 45 | + } |
48 | 46 | }
|
0 commit comments