mirror of
https://github.com/certd/certd.git
synced 2026-04-23 11:37:23 +08:00
perf: 流水线支持名称模糊查询
This commit is contained in:
@@ -23,9 +23,19 @@ export class PipelineController extends CrudController<PipelineService> {
|
||||
@Post('/page', { summary: Constants.per.authOnly })
|
||||
async page(@Body(ALL) body) {
|
||||
body.query.userId = this.ctx.user.id;
|
||||
|
||||
const title = body.query.title;
|
||||
delete body.query.title;
|
||||
|
||||
const buildQuery = qb => {
|
||||
qb.where({});
|
||||
if (title) {
|
||||
qb.where('title like :title', { title: `%${title}%` });
|
||||
}
|
||||
};
|
||||
if (!body.sort || !body.sort?.prop) {
|
||||
body.sort = { prop: 'order', asc: false };
|
||||
}
|
||||
|
||||
return super.page({ ...body, buildQuery });
|
||||
}
|
||||
|
||||
@@ -48,7 +58,6 @@ export class PipelineController extends CrudController<PipelineService> {
|
||||
await this.service.checkUserId(bean.id, this.ctx.user.id);
|
||||
}
|
||||
await this.service.save(bean);
|
||||
await this.service.registerTriggerById(bean.id);
|
||||
return this.ok(bean.id);
|
||||
}
|
||||
|
||||
|
||||
@@ -37,6 +37,16 @@ export class PipelineEntity {
|
||||
})
|
||||
lastHistoryTime: number;
|
||||
|
||||
// 变量
|
||||
lastVars: any;
|
||||
|
||||
@Column({
|
||||
name: 'order',
|
||||
comment: '排序',
|
||||
nullable: true,
|
||||
})
|
||||
order: number;
|
||||
|
||||
@Column({
|
||||
name: 'create_time',
|
||||
comment: '创建时间',
|
||||
|
||||
@@ -12,7 +12,7 @@ export class DbStorage implements IStorage {
|
||||
this.storageService = storageService;
|
||||
}
|
||||
|
||||
remove(scope: string, namespace: string, version: string, key: string): Promise<void> {
|
||||
async remove(scope: string, namespace: string, version: string, key: string): Promise<void> {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
|
||||
|
||||
@@ -47,8 +47,23 @@ export class PipelineService extends BaseService<PipelineEntity> {
|
||||
return this.repository;
|
||||
}
|
||||
|
||||
async update(entity) {
|
||||
await super.update(entity);
|
||||
async page(query: any, page: { offset: number; limit: number }, order: any, buildQuery: any) {
|
||||
const result = await super.page(query, page, order, buildQuery);
|
||||
const pipelineIds: number[] = [];
|
||||
const recordMap = {};
|
||||
for (const record of result.records) {
|
||||
pipelineIds.push(record.id);
|
||||
recordMap[record.id] = record;
|
||||
}
|
||||
const vars = await this.storageService.findPipelineVars(pipelineIds);
|
||||
for (const varEntity of vars) {
|
||||
const record = recordMap[varEntity.namespace];
|
||||
if (record) {
|
||||
const value = JSON.parse(varEntity.value);
|
||||
record.lastVars = value.value;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public async registerTriggerById(pipelineId) {
|
||||
@@ -71,10 +86,18 @@ export class PipelineService extends BaseService<PipelineEntity> {
|
||||
return new PipelineDetail(pipeline);
|
||||
}
|
||||
|
||||
async update(bean: PipelineEntity) {
|
||||
await this.clearTriggers(bean.id);
|
||||
await super.update(bean);
|
||||
await this.registerTriggerById(bean.id);
|
||||
}
|
||||
|
||||
async save(bean: PipelineEntity) {
|
||||
await this.clearTriggers(bean.id);
|
||||
const pipeline = JSON.parse(bean.content);
|
||||
bean.title = pipeline.title;
|
||||
await this.addOrUpdate(bean);
|
||||
await this.registerTriggerById(bean.id);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -153,6 +176,14 @@ export class PipelineService extends BaseService<PipelineEntity> {
|
||||
}
|
||||
|
||||
async delete(id: number) {
|
||||
await this.clearTriggers(id);
|
||||
//TODO 删除storage
|
||||
// const storage = new DbStorage(pipeline.userId, this.storageService);
|
||||
// await storage.remove(pipeline.id);
|
||||
await super.delete([id]);
|
||||
}
|
||||
|
||||
async clearTriggers(id: number) {
|
||||
const pipeline = await this.info(id);
|
||||
if (!pipeline) {
|
||||
return;
|
||||
@@ -163,7 +194,6 @@ export class PipelineService extends BaseService<PipelineEntity> {
|
||||
this.removeCron(id, trigger);
|
||||
}
|
||||
}
|
||||
await super.delete([id]);
|
||||
}
|
||||
|
||||
removeCron(pipelineId, trigger) {
|
||||
@@ -176,6 +206,7 @@ export class PipelineService extends BaseService<PipelineEntity> {
|
||||
if (cron == null) {
|
||||
return;
|
||||
}
|
||||
cron = cron.trim();
|
||||
if (cron.startsWith('*')) {
|
||||
cron = '0' + cron.substring(1, cron.length);
|
||||
}
|
||||
@@ -183,7 +214,7 @@ export class PipelineService extends BaseService<PipelineEntity> {
|
||||
this.cron.remove(name);
|
||||
this.cron.register({
|
||||
name,
|
||||
cron: cron,
|
||||
cron,
|
||||
job: async () => {
|
||||
logger.info('定时任务触发:', pipelineId, trigger.id);
|
||||
try {
|
||||
@@ -198,6 +229,9 @@ export class PipelineService extends BaseService<PipelineEntity> {
|
||||
|
||||
async run(id: number, triggerId: string) {
|
||||
const entity: PipelineEntity = await this.info(id);
|
||||
if (entity.disabled) {
|
||||
return;
|
||||
}
|
||||
const pipeline = JSON.parse(entity.content);
|
||||
|
||||
if (!pipeline.stages || pipeline.stages.length === 0) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Provide, Scope, ScopeEnum } from '@midwayjs/core';
|
||||
import { InjectEntityModel } from '@midwayjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
import { In, Repository } from 'typeorm';
|
||||
import { BaseService } from '../../../basic/base-service.js';
|
||||
import { StorageEntity } from '../entity/storage.js';
|
||||
|
||||
@@ -41,4 +41,14 @@ export class StorageService extends BaseService<StorageEntity> {
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
async findPipelineVars(pipelineIds: number[]) {
|
||||
return await this.repository.find({
|
||||
where: {
|
||||
scope: 'pipeline',
|
||||
namespace: In(pipelineIds),
|
||||
key: 'vars',
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user