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
+5 -1
View File
@@ -11,6 +11,10 @@ typeorm:
password: root
database: postgres
#plus:
# server:
# baseUrl: 'https://api.ai.handsfree.work'
plus:
server:
baseUrl: 'https://api.ai.handsfree.work'
baseUrl: 'http://127.0.0.1:11007'
@@ -3,7 +3,7 @@ import { Controller, Get, Inject, Provide } from '@midwayjs/core';
import { BaseController } from '../../../basic/base-controller.js';
import { Constants } from '../../../basic/constants.js';
import { SysSettingsService } from '../../system/service/sys-settings-service.js';
import { SysPublicSettings } from '../../system/service/models.js';
import { SysInstallInfo, SysPublicSettings } from '../../system/service/models.js';
export class SmsCodeReq {
@Rule(RuleType.number().required())
@@ -32,4 +32,10 @@ export class BasicSettingsController extends BaseController {
const settings = await this.sysSettingsService.getSetting(SysPublicSettings);
return this.ok(settings);
}
@Get('/install', { summary: Constants.per.guest })
public async getInstallInfo() {
const settings = await this.sysSettingsService.getSetting(SysInstallInfo);
return this.ok(settings);
}
}
@@ -1,7 +1,7 @@
import { Config, Inject, Provide, Scope, ScopeEnum } from '@midwayjs/core';
import { SysSettingsService } from '../../system/service/sys-settings-service.js';
import { SysInstallInfo } from '../../system/service/models.js';
import { appKey, getPlusInfo, isPlus } from '@certd/pipeline';
import { AppKey, getPlusInfo, isPlus } from '@certd/pipeline';
import * as crypto from 'crypto';
import { request } from '../../../utils/http.js';
import { logger } from '../../../utils/logger.js';
@@ -30,7 +30,7 @@ export class PlusService {
const requestHeader = {
subjectId: installInfo.siteId,
appKey: appKey,
appKey: AppKey,
sign: sign,
timestamps: timestamps,
};
@@ -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');
}
}
@@ -1,7 +1,7 @@
import { ALL, Body, Controller, Inject, Post, Provide } from '@midwayjs/core';
import { SysSettingsService } from '../service/sys-settings-service.js';
import { BaseController } from '../../../basic/base-controller.js';
import { appKey, verify } from '@certd/pipeline';
import { AppKey, verify } from '@certd/pipeline';
import { SysInstallInfo, SysLicenseInfo } from '../service/models.js';
import { logger } from '../../../utils/logger.js';
import { PlusService } from '../../basic/service/plus-service.js';
@@ -22,7 +22,7 @@ export class SysPlusController extends BaseController {
const { code } = body;
const installInfo: SysInstallInfo = await this.sysSettingsService.getSetting(SysInstallInfo);
const formData = {
appKey: appKey,
appKey: AppKey,
code,
subjectId: installInfo.siteId,
};