Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
Toggle navigation
This project
Loading...
Sign in
毛树良
/
VVAS-DataCenter-DBWriter
Go to a project
Project
Repository
Merge Requests
0
Pipelines
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 78a1eb91
authored
Nov 20, 2025
by
文帅营
Browse Files
Options
Browse Files
Tag
Download
Plain Diff
Merge remote-tracking branch 'origin/store' into store
2 parents
672edbf5
b85ada89
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
0 deletions
src/main/java/com/viontech/keliu/cron/TopicCleanupJob.java
src/main/java/com/viontech/keliu/cron/TopicCleanupJob.java
View file @
78a1eb9
...
@@ -4,7 +4,9 @@ import cn.hutool.core.date.DateTime;
...
@@ -4,7 +4,9 @@ import cn.hutool.core.date.DateTime;
import
cn.hutool.core.date.DateUtil
;
import
cn.hutool.core.date.DateUtil
;
import
com.viontech.keliu.service.KafkaTopicService
;
import
com.viontech.keliu.service.KafkaTopicService
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.data.redis.core.RedisTemplate
;
import
org.springframework.scheduling.annotation.Scheduled
;
import
org.springframework.scheduling.annotation.Scheduled
;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Component
;
...
@@ -12,6 +14,7 @@ import javax.annotation.Resource;
...
@@ -12,6 +14,7 @@ import javax.annotation.Resource;
import
java.time.LocalDate
;
import
java.time.LocalDate
;
import
java.time.ZoneId
;
import
java.time.ZoneId
;
import
java.util.Date
;
import
java.util.Date
;
import
java.util.concurrent.TimeUnit
;
/**
/**
* kafka topic 清理任务
* kafka topic 清理任务
...
@@ -25,9 +28,19 @@ public class TopicCleanupJob {
...
@@ -25,9 +28,19 @@ public class TopicCleanupJob {
private
Integer
preDay
;
private
Integer
preDay
;
@Resource
@Resource
private
KafkaTopicService
kafkaTopicService
;
private
KafkaTopicService
kafkaTopicService
;
@Autowired
private
RedisTemplate
redisTemplate
;
// TopicCleanupJob的分布式锁
private
static
final
String
TOPICCLEANUPJOB_LOCK_KEY
=
"lock:TopicCleanupJob:"
;
@Scheduled
(
cron
=
"${vion.topicCleanup.cron:-}"
)
@Scheduled
(
cron
=
"${vion.topicCleanup.cron:-}"
)
public
void
doTopicCleanup
()
{
public
void
doTopicCleanup
()
{
String
lockKey
=
TOPICCLEANUPJOB_LOCK_KEY
+
DateUtil
.
format
(
new
Date
(),
"yyyyMMdd"
);
Boolean
locked
=
redisTemplate
.
opsForValue
().
setIfAbsent
(
lockKey
,
"1"
,
2
,
TimeUnit
.
DAYS
);
log
.
info
(
"doTopicCleanup.lockKey {}={}"
,
lockKey
,
locked
);
if
(
locked
!=
null
&&
!
locked
)
{
return
;
}
DateTime
preDate
=
DateUtil
.
offsetDay
(
new
Date
(),
preDay
*
(-
1
));
DateTime
preDate
=
DateUtil
.
offsetDay
(
new
Date
(),
preDay
*
(-
1
));
DateTime
countDate
=
DateUtil
.
beginOfDay
(
preDate
);
DateTime
countDate
=
DateUtil
.
beginOfDay
(
preDate
);
LocalDate
maxCountDate
=
countDate
.
toInstant
().
atZone
(
ZoneId
.
of
(
"Asia/Shanghai"
)).
toLocalDate
();
LocalDate
maxCountDate
=
countDate
.
toInstant
().
atZone
(
ZoneId
.
of
(
"Asia/Shanghai"
)).
toLocalDate
();
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment