perf: 同一时间只允许一个套餐生效

This commit is contained in:
xiaojunnuo
2024-12-24 10:39:54 +08:00
parent 7f596ed315
commit 8ebf95a222
10 changed files with 120 additions and 86 deletions
@@ -57,6 +57,7 @@ CREATE TABLE "cd_user_suite"
"deploy_count_used" integer,
"is_present" boolean,
"is_bootstrap" boolean,
"is_empty" boolean,
"disabled" boolean NOT NULL DEFAULT (false),
"active_time" integer,
"expires_time" integer,
@@ -72,7 +72,7 @@ const development = {
type: 'better-sqlite3',
database: './data/db.sqlite',
synchronize: false, // 如果第一次使用,不存在表,有同步的需求可以写 true
logging: false,
logging: true,
highlightSql: false,
// 配置实体模型 或者 entities: '/entity',
@@ -34,7 +34,7 @@ import { logger } from '@certd/basic';
import { UrlService } from './url-service.js';
import { NotificationService } from './notification-service.js';
import { NotificationGetter } from './notification-getter.js';
import { UserSuiteService } from '@certd/commercial-core';
import { UserSuiteEntity, UserSuiteService } from '@certd/commercial-core';
import { CertInfoService } from '../../monitor/service/cert-info-service.js';
const runningTasks: Map<string | number, Executor> = new Map();
@@ -391,6 +391,11 @@ export class PipelineService extends BaseService<PipelineEntity> {
async run(id: number, triggerId: string, stepId?: string) {
const entity: PipelineEntity = await this.info(id);
let suite: UserSuiteEntity = null;
if (isComm()) {
suite = await this.userSuiteService.checkHasDeployCount(entity.userId);
}
const pipeline = JSON.parse(entity.content);
if (!pipeline.id) {
pipeline.id = id;
@@ -464,7 +469,14 @@ export class PipelineService extends BaseService<PipelineEntity> {
// 清除该step的状态
executor.clearLastStatus(stepId);
}
await executor.run(historyId, triggerType);
const result = await executor.run(historyId, triggerType);
if (result === ResultType.success) {
if (isComm()) {
// 消耗成功次数
await this.userSuiteService.consumeDeployCount(suite, 1);
}
}
} catch (e) {
logger.error('执行失败:', e);
// throw e;