录单
This commit is contained in:
@@ -452,8 +452,8 @@ public class JDScheduleJob {
|
||||
|
||||
@Scheduled(cron = "0 0 8-20 * * ?") // 每天从 8:00 到 20:00,每小时执行一次
|
||||
public void fetchPL() {
|
||||
logger.info("开始执行fetchPL任务");
|
||||
// 设置每天最多执行 3 次
|
||||
String cacheKey = "fetchPL:executedHours";
|
||||
Set<String> executedHours = getExecutedHoursFromRedis(); // 从 Redis 获取已执行的小时数
|
||||
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
@@ -461,11 +461,13 @@ public void fetchPL() {
|
||||
|
||||
// 如果今天已经执行了3次,则跳过
|
||||
if (executedHours.size() >= 3) {
|
||||
logger.info("今天已经执行了3次,跳过本次任务");
|
||||
return;
|
||||
}
|
||||
|
||||
// 随机决定是否执行本次任务(例如 50% 概率)
|
||||
if (new Random().nextBoolean()) {
|
||||
logger.info("执行fetchPL任务");
|
||||
// 执行任务逻辑
|
||||
executeFetchPL();
|
||||
// 记录该小时已执行
|
||||
@@ -477,14 +479,13 @@ public void fetchPL() {
|
||||
|
||||
private void executeFetchPL() {
|
||||
HashMap<String, String> productTypeMap = jdUtil.getProductTypeMap();
|
||||
int allCommentCount = 0;
|
||||
int usedCommentCount = 0;
|
||||
int canUseComentCount = 0;
|
||||
int addCommentCount = 0;
|
||||
int usedCommentCount;
|
||||
int canUseComentCount;
|
||||
int addCommentCount;
|
||||
for (Map.Entry<String, String> entry : productTypeMap.entrySet()) {
|
||||
|
||||
// 随机睡眠1-5分钟
|
||||
int sleepTime = new Random().nextInt(300) + 60;
|
||||
int sleepTime = new Random().nextInt(3000) + 60;
|
||||
try {
|
||||
Thread.sleep(sleepTime * 1000);
|
||||
} catch (InterruptedException e) {
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
# ????????????
|
||||
log4j.rootLogger=DEBUG, file
|
||||
|
||||
# ?????? Appender
|
||||
log4j.appender.file=org.apache.log4j.RollingFileAppender
|
||||
log4j.appender.file.File=logs/app.log
|
||||
log4j.appender.file.MaxFileSize=10MB
|
||||
log4j.appender.file.MaxBackupIndex=30
|
||||
log4j.appender.file.layout=org.apache.log4j.PatternLayout
|
||||
log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} [%t] %-5p %c - %m%n
|
||||
24
src/main/resources/logback-spring.xml
Normal file
24
src/main/resources/logback-spring.xml
Normal file
@@ -0,0 +1,24 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<configuration>
|
||||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<pattern>%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<root level="INFO">
|
||||
<appender-ref ref="STDOUT"/>
|
||||
</root>
|
||||
<appender name="FILE" class="ch.qos.logback.core.FileAppender">
|
||||
<file>logs/app.log</file>
|
||||
<encoder>
|
||||
<pattern>%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<root level="DEBUG">
|
||||
<appender-ref ref="STDOUT"/>
|
||||
<appender-ref ref="FILE"/>
|
||||
</root>
|
||||
|
||||
</configuration>
|
||||
Reference in New Issue
Block a user