Commit 04e218166cfaebf24ecec46773bdfbd125c20103
1 parent
04ec8489
Minor Improvements to Alarms Cleanup
Showing
1 changed file
with
7 additions
and
5 deletions
... | ... | @@ -26,6 +26,7 @@ import org.thingsboard.server.common.data.id.AlarmId; |
26 | 26 | import org.thingsboard.server.common.data.id.TenantId; |
27 | 27 | import org.thingsboard.server.common.data.page.PageData; |
28 | 28 | import org.thingsboard.server.common.data.page.PageLink; |
29 | +import org.thingsboard.server.common.data.page.SortOrder; | |
29 | 30 | import org.thingsboard.server.common.data.tenant.profile.DefaultTenantProfileConfiguration; |
30 | 31 | import org.thingsboard.server.common.msg.queue.ServiceType; |
31 | 32 | import org.thingsboard.server.dao.alarm.AlarmDao; |
... | ... | @@ -35,6 +36,7 @@ import org.thingsboard.server.dao.tenant.TbTenantProfileCache; |
35 | 36 | import org.thingsboard.server.dao.tenant.TenantDao; |
36 | 37 | import org.thingsboard.server.dao.util.PsqlDao; |
37 | 38 | import org.thingsboard.server.queue.discovery.PartitionService; |
39 | +import org.thingsboard.server.queue.util.TbCoreComponent; | |
38 | 40 | import org.thingsboard.server.service.action.RuleEngineEntityActionService; |
39 | 41 | import org.thingsboard.server.service.ttl.AbstractCleanUpService; |
40 | 42 | |
... | ... | @@ -45,7 +47,7 @@ import java.util.Optional; |
45 | 47 | import java.util.UUID; |
46 | 48 | import java.util.concurrent.TimeUnit; |
47 | 49 | |
48 | -@PsqlDao | |
50 | +@TbCoreComponent | |
49 | 51 | @Service |
50 | 52 | @Slf4j |
51 | 53 | @RequiredArgsConstructor |
... | ... | @@ -64,7 +66,7 @@ public class AlarmsCleanUpService { |
64 | 66 | @Scheduled(initialDelayString = "#{T(org.apache.commons.lang3.RandomUtils).nextLong(0, ${sql.ttl.alarms.checking_interval})}", fixedDelayString = "${sql.ttl.alarms.checking_interval}") |
65 | 67 | public void cleanUp() { |
66 | 68 | PageLink tenantsBatchRequest = new PageLink(10_000, 0); |
67 | - PageLink removalBatchRequest = new PageLink(removalBatchSize, 0); | |
69 | + PageLink removalBatchRequest = new PageLink(removalBatchSize, 0 ); | |
68 | 70 | PageData<TenantId> tenantsIds; |
69 | 71 | do { |
70 | 72 | tenantsIds = tenantDao.findTenantsIds(tenantsBatchRequest); |
... | ... | @@ -79,11 +81,11 @@ public class AlarmsCleanUpService { |
79 | 81 | } |
80 | 82 | |
81 | 83 | long ttl = TimeUnit.DAYS.toMillis(tenantProfileConfiguration.get().getAlarmsTtlDays()); |
82 | - long outdatageTime = System.currentTimeMillis() - ttl; | |
84 | + long expirationTime = System.currentTimeMillis() - ttl; | |
83 | 85 | |
84 | 86 | long totalRemoved = 0; |
85 | 87 | while (true) { |
86 | - PageData<AlarmId> toRemove = alarmDao.findAlarmsIdsByEndTsBeforeAndTenantId(outdatageTime, tenantId, removalBatchRequest); | |
88 | + PageData<AlarmId> toRemove = alarmDao.findAlarmsIdsByEndTsBeforeAndTenantId(expirationTime, tenantId, removalBatchRequest); | |
87 | 89 | toRemove.getData().forEach(alarmId -> { |
88 | 90 | relationService.deleteEntityRelations(tenantId, alarmId); |
89 | 91 | Alarm alarm = alarmService.deleteAlarm(tenantId, alarmId).getAlarm(); |
... | ... | @@ -97,7 +99,7 @@ public class AlarmsCleanUpService { |
97 | 99 | } |
98 | 100 | |
99 | 101 | if (totalRemoved > 0) { |
100 | - log.info("Removed {} outdated alarm(s) for tenant {} older than {}", totalRemoved, tenantId, new Date(outdatageTime)); | |
102 | + log.info("Removed {} outdated alarm(s) for tenant {} older than {}", totalRemoved, tenantId, new Date(expirationTime)); | |
101 | 103 | } |
102 | 104 | } |
103 | 105 | ... | ... |