diff --git a/packages/ui/certd-client/src/views/certd/pipeline/api.ts b/packages/ui/certd-client/src/views/certd/pipeline/api.ts index babc39ec2..391cbf1b4 100644 --- a/packages/ui/certd-client/src/views/certd/pipeline/api.ts +++ b/packages/ui/certd-client/src/views/certd/pipeline/api.ts @@ -163,3 +163,11 @@ export async function ReadCertDetail(crt: string): Promise { data: { crt }, }); } + +export async function ToggleDisabled(req: { id: number; disabled: boolean }) { + return await request({ + url: apiPrefix + "/disabled", + method: "post", + data: req, + }); +} diff --git a/packages/ui/certd-client/src/views/certd/pipeline/crud.tsx b/packages/ui/certd-client/src/views/certd/pipeline/crud.tsx index e4641dc80..f71fb8d50 100644 --- a/packages/ui/certd-client/src/views/certd/pipeline/crud.tsx +++ b/packages/ui/certd-client/src/views/certd/pipeline/crud.tsx @@ -484,9 +484,9 @@ export default function ({ crudExpose, context: { selectedRowKeys } }: CreateCru vModel: "checked", }, async valueChange({ row, key, value }) { - return await api.UpdateObj({ + return await api.ToggleDisabled({ id: row.id, - disabled: row[key], + disabled: value, }); }, }, diff --git a/packages/ui/certd-server/src/controller/user/pipeline/pipeline-controller.ts b/packages/ui/certd-server/src/controller/user/pipeline/pipeline-controller.ts index 51087b089..d0ee9eaf2 100644 --- a/packages/ui/certd-server/src/controller/user/pipeline/pipeline-controller.ts +++ b/packages/ui/certd-server/src/controller/user/pipeline/pipeline-controller.ts @@ -129,6 +129,13 @@ export class PipelineController extends CrudController { return this.ok({}); } + @Post('/disabled', { summary: Constants.per.authOnly }) + async disabled(@Body(ALL) bean) { + await this.authService.checkEntityUserId(this.ctx, this.getService(), bean.id); + delete bean.userId; + return this.service.disabled(bean.id, bean.disabled); + } + @Post('/detail', { summary: Constants.per.authOnly }) async detail(@Query('id') id: number) { await this.authService.checkEntityUserId(this.ctx, this.getService(), id); diff --git a/packages/ui/certd-server/src/modules/pipeline/service/pipeline-service.ts b/packages/ui/certd-server/src/modules/pipeline/service/pipeline-service.ts index b77b2b57f..581bf6ada 100644 --- a/packages/ui/certd-server/src/modules/pipeline/service/pipeline-service.ts +++ b/packages/ui/certd-server/src/modules/pipeline/service/pipeline-service.ts @@ -171,9 +171,14 @@ export class PipelineService extends BaseService { return; } const info = await this.info(pipelineId); - if (info && !info.disabled) { + if (!info) { + return; + } + if (!info.disabled) { const pipeline = JSON.parse(info.content); this.registerTriggers(pipeline, false); + }else { + this.unregisterTriggers(info); } } @@ -187,6 +192,8 @@ export class PipelineService extends BaseService { } } + + /** * 获取详情 * @param id @@ -256,7 +263,7 @@ export class PipelineService extends BaseService { * @param pipeline */ async doUpdatePipelineJson(bean: PipelineEntity, pipeline: Pipeline) { - await this.clearTriggers(bean); + await this.unregisterTriggers(bean); if (pipeline.title) { bean.title = pipeline.title; } @@ -347,7 +354,7 @@ export class PipelineService extends BaseService { async stopOtherUserPipeline(userId: number) { await this.foreachPipeline(async entity => { if (entity.userId !== userId) { - await this.clearTriggers(entity.id); + await this.unregisterTriggers(entity.id); } }); } @@ -389,6 +396,8 @@ export class PipelineService extends BaseService { } } + + async trigger(id: any, stepId?: string, doCheck = false) { const entity: PipelineEntity = await this.info(id); if (doCheck) { @@ -425,7 +434,7 @@ export class PipelineService extends BaseService { //@ts-ignore async delete(id: any) { - await this.clearTriggers(id); + await this.unregisterTriggers(id); //TODO 删除storage // const storage = new DbStorage(pipeline.userId, this.storageService); // await storage.remove(pipeline.id); @@ -435,7 +444,7 @@ export class PipelineService extends BaseService { await this.certInfoService.deleteByPipelineId(id); } - async clearTriggers(id: number | PipelineEntity) { + async unregisterTriggers(id: number | PipelineEntity) { if (id == null) { return; } @@ -526,6 +535,10 @@ export class PipelineService extends BaseService { */ async run(id: number, triggerId: string, stepId?: string) { const entity: PipelineEntity = await this.info(id); + if (!entity) { + logger.error(`流水线${id}不存在`); + return; + } await this.doRun(entity, triggerId, stepId); } @@ -571,8 +584,9 @@ export class PipelineService extends BaseService { return; } - if (triggerType === "timer") { + if (triggerType !== "user") { if (entity.disabled) { + logger.info(`流水线${entity.id}已禁用,不予执行`); return; } } @@ -1088,4 +1102,9 @@ export class PipelineService extends BaseService { }); return res?.userId; } + + async disabled(id: number, disabled: boolean) { + await this.repository.update(id, { disabled }); + await this.registerTriggerById(id); + } }