feat(1.1.2.0-beta3):

1、定时、重试任务清除时间一小时改为四小时
2、修复日志清除BUG
This commit is contained in:
wodeyangzipingpingwuqi 2024-10-29 14:21:03 +08:00
parent c802009c78
commit 4218bce023
2 changed files with 14 additions and 15 deletions

View File

@ -20,8 +20,6 @@ import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.google.common.collect.Lists;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.support.TransactionCallbackWithoutResult;
@ -58,7 +56,7 @@ public class JobClearLogSchedule extends AbstractSchedule implements Lifecycle {
@Override
public String lockAtMost() {
return "PT1H";
return "PT4H";
}
@Override
@ -69,8 +67,9 @@ public class JobClearLogSchedule extends AbstractSchedule implements Lifecycle {
@Override
protected void doExecute() {
try {
// 清楚日志默认保存天数大于零最少保留最近一天的日志数据
if (systemProperties.getLogStorage() <= 0 || System.currentTimeMillis() - lastCleanLogTime < 24 * 60 * 60 * 1000) {
// 清除日志默认保存天数大于零最少保留最近一天的日志数据
if (systemProperties.getLogStorage() <= 1 && System.currentTimeMillis() - lastCleanLogTime < 24 * 60 * 60 * 1000) {
SnailJobLog.LOCAL.error("job clear log storage error", systemProperties.getLogStorage());
return;
}
// clean job log
@ -80,11 +79,10 @@ public class JobClearLogSchedule extends AbstractSchedule implements Lifecycle {
this::processJobLogPartitionTasks, 0);
SnailJobLog.LOCAL.debug("Job clear success total:[{}]", total);
} catch (Exception e) {
SnailJobLog.LOCAL.error("job clear log error", e);
} finally {
// update clean time
lastCleanLogTime = System.currentTimeMillis();
} catch (Exception e) {
SnailJobLog.LOCAL.error("job clear log error", e);
}
}
@ -146,7 +144,7 @@ public class JobClearLogSchedule extends AbstractSchedule implements Lifecycle {
@Override
public void start() {
taskScheduler.scheduleAtFixedRate(this::execute, Duration.parse("PT1H"));
taskScheduler.scheduleAtFixedRate(this::execute, Duration.parse("PT4H"));
}
@Override

View File

@ -56,7 +56,7 @@ public class ClearLogSchedule extends AbstractSchedule implements Lifecycle {
@Override
public String lockAtMost() {
return "PT1H";
return "PT4H";
}
@Override
@ -67,7 +67,9 @@ public class ClearLogSchedule extends AbstractSchedule implements Lifecycle {
@Override
protected void doExecute() {
try {
if (systemProperties.getLogStorage() <= 0 || System.currentTimeMillis() - lastCleanLogTime < 24 * 60 * 60 * 1000) {
// 清除日志默认保存天数大于零最少保留最近一天的日志数据
if (systemProperties.getLogStorage() <= 1 && System.currentTimeMillis() - lastCleanLogTime < 24 * 60 * 60 * 1000) {
SnailJobLog.LOCAL.error("retry clear log storage error", systemProperties.getLogStorage());
return;
}
// clean retry log
@ -76,11 +78,10 @@ public class ClearLogSchedule extends AbstractSchedule implements Lifecycle {
this::processRetryLogPartitionTasks, 0);
SnailJobLog.LOCAL.debug("Retry clear success total:[{}]", total);
} catch (Exception e) {
SnailJobLog.LOCAL.error("clear log error", e);
} finally {
// update clean time
lastCleanLogTime = System.currentTimeMillis();
} catch (Exception e) {
SnailJobLog.LOCAL.error("clear log error", e);
}
}
@ -137,7 +138,7 @@ public class ClearLogSchedule extends AbstractSchedule implements Lifecycle {
@Override
public void start() {
taskScheduler.scheduleAtFixedRate(this::execute, Duration.parse("PT1H"));
taskScheduler.scheduleAtFixedRate(this::execute, Duration.parse("PT4H"));
}
@Override