chore: off cron when remove

pull/21/merge
xiaojunnuo 2023-06-28 12:46:29 +08:00
parent f04e497999
commit 301f6cc273
2 changed files with 21 additions and 1 deletions

View File

@ -60,7 +60,8 @@ export class PipelineController extends CrudController<PipelineService> {
@Post('/delete', { summary: Constants.per.authOnly })
async delete(@Query('id') id) {
await this.service.checkUserId(id, this.ctx.user.id);
return super.delete(id);
await this.service.delete(id);
return this.ok({});
}
@Post('/detail', { summary: Constants.per.authOnly })

View File

@ -136,6 +136,25 @@ export class PipelineService extends BaseService<PipelineEntity> {
logger.info('定时器数量:', this.cron.getListSize());
}
async delete(id: number) {
const pipeline = await this.info(id);
if (!pipeline) {
return;
}
const pipelineObj = JSON.parse(pipeline.content);
if (pipelineObj.triggers) {
for (const trigger of pipelineObj.triggers) {
this.removeCron(id, trigger);
}
}
await super.delete([id]);
}
removeCron(pipelineId, trigger) {
const name = this.buildCronKey(pipelineId, trigger.id);
this.cron.remove(name);
}
registerCron(pipelineId, trigger) {
let cron = trigger.props?.cron;
if (cron == null) {