fix: 修复执行日志没有清理的bug

This commit is contained in:
xiaojunnuo
2024-08-25 01:55:34 +08:00
parent 86ebbcb9bb
commit 22a336370a
14 changed files with 157 additions and 76 deletions
@@ -63,7 +63,7 @@ export class HistoryService extends BaseService<HistoryEntity> {
return id;
}
private async clear(pipelineId: number, keepCount = 30) {
private async clear(pipelineId: number, keepCount = 10) {
const count = await this.repository.count({
where: {
pipelineId,
@@ -73,13 +73,14 @@ export class HistoryService extends BaseService<HistoryEntity> {
return;
}
let shouldDeleteCount = count - keepCount;
const deleteCountBatch = 100;
const fileStore = new FileStore({
rootDir: this.certdConfig.fileRootDir,
scope: pipelineId + '',
parent: '0',
});
const maxDeleteCountBatch = 100;
// const fileStore = new FileStore({
// rootDir: this.certdConfig.fileRootDir,
// scope: pipelineId + '',
// parent: '0',
// });
while (shouldDeleteCount > 0) {
const deleteCountBatch = maxDeleteCountBatch > shouldDeleteCount ? shouldDeleteCount : maxDeleteCountBatch;
const list = await this.repository.find({
select: {
id: true,
@@ -94,18 +95,16 @@ export class HistoryService extends BaseService<HistoryEntity> {
take: deleteCountBatch,
});
for (const historyEntity of list) {
const id = historyEntity.id;
try {
fileStore.deleteByParent(pipelineId + '', id + '');
} catch (e) {
logger.error('删除文件失败', e);
}
}
await this.repository.remove(list);
await this.logService.deleteByHistoryIds(list.map(item => item.id));
// for (const historyEntity of list) {
// const id = historyEntity.id;
// try {
// fileStore.deleteByParent(pipelineId + '', id + '');
// } catch (e) {
// logger.error('删除文件失败', e);
// }
// }
const ids = list.map(item => item.id);
await this.deleteByIds(ids, null);
shouldDeleteCount -= deleteCountBatch;
}
}
@@ -107,7 +107,7 @@ export class PipelineService extends BaseService<PipelineEntity> {
async save(bean: PipelineEntity) {
if (!isPlus()) {
const count = await this.repository.count();
if (count >= 10) {
if (count >= freeCount) {
throw new NeedVIPException('免费版最多只能创建10个pipeline');
}
}