mirror of
https://github.com/certd/certd.git
synced 2026-04-24 12:27:25 +08:00
fix: 修复重启certd后,再启用流水线,不会自动执行的bug
This commit is contained in:
@@ -163,3 +163,11 @@ export async function ReadCertDetail(crt: string): Promise<any> {
|
|||||||
data: { crt },
|
data: { crt },
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function ToggleDisabled(req: { id: number; disabled: boolean }) {
|
||||||
|
return await request({
|
||||||
|
url: apiPrefix + "/disabled",
|
||||||
|
method: "post",
|
||||||
|
data: req,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|||||||
@@ -484,9 +484,9 @@ export default function ({ crudExpose, context: { selectedRowKeys } }: CreateCru
|
|||||||
vModel: "checked",
|
vModel: "checked",
|
||||||
},
|
},
|
||||||
async valueChange({ row, key, value }) {
|
async valueChange({ row, key, value }) {
|
||||||
return await api.UpdateObj({
|
return await api.ToggleDisabled({
|
||||||
id: row.id,
|
id: row.id,
|
||||||
disabled: row[key],
|
disabled: value,
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -129,6 +129,13 @@ export class PipelineController extends CrudController<PipelineService> {
|
|||||||
return this.ok({});
|
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 })
|
@Post('/detail', { summary: Constants.per.authOnly })
|
||||||
async detail(@Query('id') id: number) {
|
async detail(@Query('id') id: number) {
|
||||||
await this.authService.checkEntityUserId(this.ctx, this.getService(), id);
|
await this.authService.checkEntityUserId(this.ctx, this.getService(), id);
|
||||||
|
|||||||
@@ -171,9 +171,14 @@ export class PipelineService extends BaseService<PipelineEntity> {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const info = await this.info(pipelineId);
|
const info = await this.info(pipelineId);
|
||||||
if (info && !info.disabled) {
|
if (!info) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!info.disabled) {
|
||||||
const pipeline = JSON.parse(info.content);
|
const pipeline = JSON.parse(info.content);
|
||||||
this.registerTriggers(pipeline, false);
|
this.registerTriggers(pipeline, false);
|
||||||
|
}else {
|
||||||
|
this.unregisterTriggers(info);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -187,6 +192,8 @@ export class PipelineService extends BaseService<PipelineEntity> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取详情
|
* 获取详情
|
||||||
* @param id
|
* @param id
|
||||||
@@ -256,7 +263,7 @@ export class PipelineService extends BaseService<PipelineEntity> {
|
|||||||
* @param pipeline
|
* @param pipeline
|
||||||
*/
|
*/
|
||||||
async doUpdatePipelineJson(bean: PipelineEntity, pipeline: Pipeline) {
|
async doUpdatePipelineJson(bean: PipelineEntity, pipeline: Pipeline) {
|
||||||
await this.clearTriggers(bean);
|
await this.unregisterTriggers(bean);
|
||||||
if (pipeline.title) {
|
if (pipeline.title) {
|
||||||
bean.title = pipeline.title;
|
bean.title = pipeline.title;
|
||||||
}
|
}
|
||||||
@@ -347,7 +354,7 @@ export class PipelineService extends BaseService<PipelineEntity> {
|
|||||||
async stopOtherUserPipeline(userId: number) {
|
async stopOtherUserPipeline(userId: number) {
|
||||||
await this.foreachPipeline(async entity => {
|
await this.foreachPipeline(async entity => {
|
||||||
if (entity.userId !== userId) {
|
if (entity.userId !== userId) {
|
||||||
await this.clearTriggers(entity.id);
|
await this.unregisterTriggers(entity.id);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -389,6 +396,8 @@ export class PipelineService extends BaseService<PipelineEntity> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
async trigger(id: any, stepId?: string, doCheck = false) {
|
async trigger(id: any, stepId?: string, doCheck = false) {
|
||||||
const entity: PipelineEntity = await this.info(id);
|
const entity: PipelineEntity = await this.info(id);
|
||||||
if (doCheck) {
|
if (doCheck) {
|
||||||
@@ -425,7 +434,7 @@ export class PipelineService extends BaseService<PipelineEntity> {
|
|||||||
|
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
async delete(id: any) {
|
async delete(id: any) {
|
||||||
await this.clearTriggers(id);
|
await this.unregisterTriggers(id);
|
||||||
//TODO 删除storage
|
//TODO 删除storage
|
||||||
// const storage = new DbStorage(pipeline.userId, this.storageService);
|
// const storage = new DbStorage(pipeline.userId, this.storageService);
|
||||||
// await storage.remove(pipeline.id);
|
// await storage.remove(pipeline.id);
|
||||||
@@ -435,7 +444,7 @@ export class PipelineService extends BaseService<PipelineEntity> {
|
|||||||
await this.certInfoService.deleteByPipelineId(id);
|
await this.certInfoService.deleteByPipelineId(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
async clearTriggers(id: number | PipelineEntity) {
|
async unregisterTriggers(id: number | PipelineEntity) {
|
||||||
if (id == null) {
|
if (id == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -526,6 +535,10 @@ export class PipelineService extends BaseService<PipelineEntity> {
|
|||||||
*/
|
*/
|
||||||
async run(id: number, triggerId: string, stepId?: string) {
|
async run(id: number, triggerId: string, stepId?: string) {
|
||||||
const entity: PipelineEntity = await this.info(id);
|
const entity: PipelineEntity = await this.info(id);
|
||||||
|
if (!entity) {
|
||||||
|
logger.error(`流水线${id}不存在`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
await this.doRun(entity, triggerId, stepId);
|
await this.doRun(entity, triggerId, stepId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -571,8 +584,9 @@ export class PipelineService extends BaseService<PipelineEntity> {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (triggerType === "timer") {
|
if (triggerType !== "user") {
|
||||||
if (entity.disabled) {
|
if (entity.disabled) {
|
||||||
|
logger.info(`流水线${entity.id}已禁用,不予执行`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1088,4 +1102,9 @@ export class PipelineService extends BaseService<PipelineEntity> {
|
|||||||
});
|
});
|
||||||
return res?.userId;
|
return res?.userId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async disabled(id: number, disabled: boolean) {
|
||||||
|
await this.repository.update(id, { disabled });
|
||||||
|
await this.registerTriggerById(id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user