mirror of
https://github.com/PowerJob/PowerJob.git
synced 2025-07-17 00:00:04 +08:00
根据意见重构代码
This commit is contained in:
parent
05181c34ec
commit
0daa097d20
@ -54,6 +54,8 @@ public class CleanService {
|
||||
// 每天凌晨3点定时清理
|
||||
private static final String CLEAN_TIME_EXPRESSION = "0 0 3 * * ?";
|
||||
|
||||
private static final String HISTORY_DELETE_LOCK = "history_delete";
|
||||
|
||||
|
||||
@Async("omsTimingPool")
|
||||
@Scheduled(cron = CLEAN_TIME_EXPRESSION)
|
||||
@ -62,18 +64,35 @@ public class CleanService {
|
||||
// 释放本地缓存
|
||||
WorkerManagerService.cleanUp();
|
||||
|
||||
// 删除数据库运行记录
|
||||
cleanInstanceLog();
|
||||
cleanWorkflowInstanceLog();
|
||||
|
||||
// 释放磁盘空间
|
||||
cleanLocal(OmsFileUtils.genLogDirPath(), instanceInfoRetentionDay);
|
||||
cleanLocal(OmsFileUtils.genContainerJarPath(), localContainerRetentionDay);
|
||||
cleanLocal(OmsFileUtils.genTemporaryPath(), TEMPORARY_RETENTION_DAY);
|
||||
|
||||
// 删除 GridFS 过期文件
|
||||
cleanRemote(GridFsManager.LOG_BUCKET, instanceInfoRetentionDay);
|
||||
cleanRemote(GridFsManager.CONTAINER_BUCKET, remoteContainerRetentionDay);
|
||||
// 删除数据库历史的数据
|
||||
cleanOneServer();
|
||||
}
|
||||
|
||||
/**
|
||||
* 只能一台server清理的操作统一到这里执行
|
||||
*/
|
||||
private void cleanOneServer() {
|
||||
// 只要第一个server抢到锁其他server就会返回,所以锁10分钟应该足够了
|
||||
boolean lock = lockService.lock(HISTORY_DELETE_LOCK, 10 * 60 * 1000);
|
||||
if (!lock) {
|
||||
log.info("[GridFsManager] deleted task is running, just return.");
|
||||
return;
|
||||
}
|
||||
try {
|
||||
// 删除数据库运行记录
|
||||
cleanInstanceLog();
|
||||
cleanWorkflowInstanceLog();
|
||||
// 删除 GridFS 过期文件
|
||||
cleanRemote(GridFsManager.LOG_BUCKET, instanceInfoRetentionDay);
|
||||
cleanRemote(GridFsManager.CONTAINER_BUCKET, remoteContainerRetentionDay);
|
||||
}finally {
|
||||
lockService.unlock(HISTORY_DELETE_LOCK);
|
||||
}
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
@ -116,20 +135,11 @@ public class CleanService {
|
||||
return;
|
||||
}
|
||||
if (gridFsManager.available()) {
|
||||
String deleteFsLock = "deleteFsLock";
|
||||
// 只要第一个server抢到锁其他server就会返回,所以锁10分钟应该足够了
|
||||
boolean lock = lockService.lock(deleteFsLock, 10 * 60 * 1000);
|
||||
if (!lock) {
|
||||
log.info("[GridFsManager] deleted task is running, just return.");
|
||||
return;
|
||||
}
|
||||
Stopwatch stopwatch = Stopwatch.createStarted();
|
||||
try {
|
||||
gridFsManager.deleteBefore(bucketName, day);
|
||||
}catch (Exception e) {
|
||||
log.warn("[CleanService] clean remote bucket({}) failed.", bucketName, e);
|
||||
}finally {
|
||||
lockService.unlock(deleteFsLock);
|
||||
}
|
||||
log.info("[CleanService] clean remote bucket({}) successfully, using {}.", bucketName, stopwatch.stop());
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user