异常记录检测修改
This commit is contained in:
+15
-5
@@ -19,6 +19,7 @@ import java.util.regex.Pattern;
|
||||
public class LocalTempCleanupService {
|
||||
|
||||
private static final Pattern ROOT_TEMP_FILE_PATTERN = Pattern.compile("^[a-fA-F0-9]{32}(\\.[^.]+)?$");
|
||||
private static final String TRANSIENT_PAYLOAD_DIR_NAME = "transient-payload";
|
||||
private static final List<String> RESULT_DIR_NAMES = List.of(
|
||||
"dedupe-result",
|
||||
"convert-result",
|
||||
@@ -39,11 +40,14 @@ public class LocalTempCleanupService {
|
||||
return;
|
||||
}
|
||||
|
||||
Instant sourceExpireBefore = Instant.now().minus(storageProperties.getSourceRetentionHours(), ChronoUnit.HOURS);
|
||||
Instant resultExpireBefore = Instant.now().minus(storageProperties.getResultRetentionHours(), ChronoUnit.HOURS);
|
||||
Instant now = Instant.now();
|
||||
Instant sourceExpireBefore = now.minus(storageProperties.getSourceRetentionHours(), ChronoUnit.HOURS);
|
||||
Instant resultExpireBefore = now.minus(storageProperties.getResultRetentionHours(), ChronoUnit.HOURS);
|
||||
Instant transientPayloadExpireBefore = now.minus(storageProperties.getTransientPayloadRetentionHours(), ChronoUnit.HOURS);
|
||||
|
||||
int deletedSourceCount = 0;
|
||||
int deletedResultCount = 0;
|
||||
int deletedTransientPayloadCount = 0;
|
||||
File[] children = tempDir.listFiles();
|
||||
if (children == null || children.length == 0) {
|
||||
return;
|
||||
@@ -60,14 +64,20 @@ public class LocalTempCleanupService {
|
||||
if (child.isDirectory() && RESULT_DIR_NAMES.contains(child.getName())) {
|
||||
deletedResultCount += deleteExpiredChildrenRecursively(child, resultExpireBefore);
|
||||
deleteEmptyDirectories(child, tempDir);
|
||||
continue;
|
||||
}
|
||||
if (child.isDirectory() && TRANSIENT_PAYLOAD_DIR_NAME.equals(child.getName())) {
|
||||
deletedTransientPayloadCount += deleteExpiredChildrenRecursively(child, transientPayloadExpireBefore);
|
||||
deleteEmptyDirectories(child, tempDir);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
log.warn("清理本地临时文件失败: path={}", child.getAbsolutePath(), ex);
|
||||
log.warn("local temp cleanup failed: path={}", child.getAbsolutePath(), ex);
|
||||
}
|
||||
}
|
||||
|
||||
if (deletedSourceCount > 0 || deletedResultCount > 0) {
|
||||
log.info("本地临时目录清理完成: sourceDeleted={}, resultDeleted={}, tempDir={}", deletedSourceCount, deletedResultCount, tempDir.getAbsolutePath());
|
||||
if (deletedSourceCount > 0 || deletedResultCount > 0 || deletedTransientPayloadCount > 0) {
|
||||
log.info("local temp cleanup completed: sourceDeleted={}, resultDeleted={}, transientPayloadDeleted={}, tempDir={}",
|
||||
deletedSourceCount, deletedResultCount, deletedTransientPayloadCount, tempDir.getAbsolutePath());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user