Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Sign in
Toggle navigation
T
tanpu-community
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
探普后端
tanpu-community
Commits
e245a591
Commit
e245a591
authored
Mar 07, 2022
by
王亚雷
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修复话题通知定时任务重复运行bug
parent
3c34fb02
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
46 additions
and
4 deletions
+46
-4
ConJobManager.java
.../main/java/com/tanpu/community/manager/ConJobManager.java
+46
-4
No files found.
community-service/src/main/java/com/tanpu/community/manager/ConJobManager.java
View file @
e245a591
package
com
.
tanpu
.
community
.
manager
;
import
com.tanpu.common.redis.RedisHelper
;
import
com.tanpu.common.uuid.UuidGenHelper
;
import
com.tanpu.community.service.*
;
import
com.tanpu.community.service.quartz.TopicReportService
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.scheduling.annotation.Scheduled
;
import
org.springframework.stereotype.Service
;
import
javax.annotation.Resource
;
import
java.time.Duration
;
@Slf4j
@Service
@Configuration
...
...
@@ -31,6 +37,12 @@ public class ConJobManager {
@Autowired
private
TopicReportService
topicReportService
;
@Resource
private
RedisHelper
redisHelper
;
@Resource
private
UuidGenHelper
uuidGenHelper
;
/**
* 定时统计 话题 访问数据,并刷到redis
*/
...
...
@@ -72,8 +84,23 @@ public class ConJobManager {
*/
@Scheduled
(
cron
=
"0 30 9 ? * *"
)
public
void
reportTopicWeekday
()
{
log
.
info
(
"reportTopicWeekday start"
);
topicReportService
.
reportTopicWeekday
();
String
key
=
"community:lock:reportTopicWeekday"
;
String
uuid
=
uuidGenHelper
.
getUuidStr
();
Boolean
locked
=
null
;
try
{
locked
=
redisHelper
.
setIfAbsent
(
key
,
uuid
,
Duration
.
ofSeconds
(
60
));
if
(
locked
)
{
log
.
info
(
"reportTopicWeekday start"
);
topicReportService
.
reportTopicWeekday
();
}
}
finally
{
if
(
Boolean
.
TRUE
.
equals
(
locked
))
{
String
value
=
redisHelper
.
get
(
key
);
if
(
StringUtils
.
equals
(
uuid
,
value
))
{
redisHelper
.
delete
(
key
);
}
}
}
}
/**
...
...
@@ -81,7 +108,22 @@ public class ConJobManager {
*/
@Scheduled
(
cron
=
"0 0 9 ? * SAT"
)
public
void
reportTopicSaturday
()
{
log
.
info
(
"reportTopicSaturday start"
);
topicReportService
.
reportTopicSaturday
();
String
key
=
"community:lock:reportTopicSaturday"
;
String
uuid
=
uuidGenHelper
.
getUuidStr
();
Boolean
locked
=
null
;
try
{
locked
=
redisHelper
.
setIfAbsent
(
key
,
uuid
,
Duration
.
ofSeconds
(
60
));
if
(
locked
)
{
log
.
info
(
"reportTopicSaturday start"
);
topicReportService
.
reportTopicSaturday
();
}
}
finally
{
if
(
Boolean
.
TRUE
.
equals
(
locked
))
{
String
value
=
redisHelper
.
get
(
key
);
if
(
StringUtils
.
equals
(
uuid
,
value
))
{
redisHelper
.
delete
(
key
);
}
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
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 comment