TopicCleanupJob.java
1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package com.viontech.keliu.cron;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import com.viontech.keliu.service.KafkaTopicService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.time.LocalDate;
import java.time.ZoneId;
import java.util.Date;
/**
* kafka topic 清理任务
* @author: msl
* Date: 2025/5/30
*/
@Slf4j
@Component
public class TopicCleanupJob {
@Value("${vion.topicCleanup.preDay:7}")
private Integer preDay;
@Resource
private KafkaTopicService kafkaTopicService;
@Scheduled(cron = "${vion.topicCleanup.cron:-}")
public void doTopicCleanup() {
DateTime preDate = DateUtil.offsetDay(new Date(), preDay * (-1));
DateTime countDate = DateUtil.beginOfDay(preDate);
LocalDate maxCountDate = countDate.toInstant().atZone(ZoneId.of("Asia/Shanghai")).toLocalDate();
log.info("doTopicCleanup execute start, preDay: {}, countDate: {}", preDay, maxCountDate);
try {
kafkaTopicService.deleteEmptyTopicsByTopicDate("Mall_FaceCapture_.*", maxCountDate);
} catch (Exception e) {
log.error("doTopicCleanup[Mall_FaceCapture_].Exception={}", e.getMessage(), e);
}
log.info("doTopicCleanup execute[Mall_FaceCapture_] end, preDay: {}, countDate: {}", preDay, maxCountDate);
try {
kafkaTopicService.deleteEmptyTopicsByTopicDate("Mall_PersonLabel_.*", maxCountDate);
} catch (Exception e) {
log.error("doTopicCleanup[Mall_PersonLabel_].Exception={}", e.getMessage(), e);
}
log.info("doTopicCleanup execute[Mall_PersonLabel_] end, preDay: {}, countDate: {}", preDay, maxCountDate);
log.info("doTopicCleanup execute end, preDay: {}, countDate: {}", preDay, maxCountDate);
}
}