refactor(系统): 资源id不存在可能导致整个任务停止了的潜在问题

This commit is contained in:
WangXu10 2024-04-12 14:31:48 +08:00 committed by Craftsman
parent d2419e0f33
commit 9e3799b5f2
1 changed files with 18 additions and 12 deletions

View File

@ -36,7 +36,7 @@ public class CleanHistoryJob {
/**
* 清理变更历史 每天凌晨两点执行
*/
@QuartzScheduled(cron = "0 0 2 * * ?")
@QuartzScheduled(cron = "0 34 13 * * ?")
public void cleanupLog() {
LogUtils.info("clean up history start.");
SystemParameter parameter = systemParameterMapper.selectByPrimaryKey(ParamConstants.CleanConfig.OPERATION_HISTORY.getValue());
@ -56,12 +56,16 @@ public class CleanHistoryJob {
}
private void doCleanupHistory(int limit) {
try {
//变更历史处理
List<String> sourceIds = baseOperationHistoryMapper.selectSourceIds();
int size = 100;
List<List<String>> batchList = splitList(sourceIds, size);
batchList.forEach(batch -> cleanupHistory(batch, limit));
} catch (Exception e) {
LogUtils.error(e);
}
}
private List<List<String>> splitList(List<String> list, int size) {
@ -75,6 +79,7 @@ public class CleanHistoryJob {
public void cleanupHistory(List<String> batch, int limit) {
batch.forEach(sourceId -> {
List<Long> ids = baseOperationHistoryMapper.selectIdsBySourceId(sourceId, limit);
if (CollectionUtils.isNotEmpty(ids)) {
baseOperationHistoryMapper.deleteByIds(sourceId, ids);
List<Long> logIds = baseOperationLogMapper.selectIdByHistoryIds(ids);
ids.removeAll(logIds);
@ -83,6 +88,7 @@ public class CleanHistoryJob {
blobExample.createCriteria().andIdIn(ids);
operationLogBlobMapper.deleteByExample(blobExample);
}
}
});
}
}