mirror of https://github.com/certd/certd
chore: 修复pipelineid为空被注册任务
parent
3f0a10007c
commit
2182dce07c
|
@ -73,6 +73,7 @@ export class PipelineService extends BaseService<PipelineEntity> {
|
||||||
const info = await this.info(pipelineId);
|
const info = await this.info(pipelineId);
|
||||||
if (info && !info.disabled) {
|
if (info && !info.disabled) {
|
||||||
const pipeline = JSON.parse(info.content);
|
const pipeline = JSON.parse(info.content);
|
||||||
|
// 手动触发,不要await
|
||||||
this.registerTriggers(pipeline);
|
this.registerTriggers(pipeline);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -173,7 +174,7 @@ export class PipelineService extends BaseService<PipelineEntity> {
|
||||||
|
|
||||||
if (immediateTriggerOnce) {
|
if (immediateTriggerOnce) {
|
||||||
await this.trigger(pipeline.id);
|
await this.trigger(pipeline.id);
|
||||||
await sleep(1000);
|
await sleep(200);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -224,6 +225,11 @@ export class PipelineService extends BaseService<PipelineEntity> {
|
||||||
}
|
}
|
||||||
|
|
||||||
registerCron(pipelineId, trigger) {
|
registerCron(pipelineId, trigger) {
|
||||||
|
if (pipelineId == null) {
|
||||||
|
logger.warn('pipelineId为空,无法注册定时任务');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
let cron = trigger.props?.cron;
|
let cron = trigger.props?.cron;
|
||||||
if (cron == null) {
|
if (cron == null) {
|
||||||
return;
|
return;
|
||||||
|
@ -232,15 +238,20 @@ export class PipelineService extends BaseService<PipelineEntity> {
|
||||||
if (cron.startsWith('*')) {
|
if (cron.startsWith('*')) {
|
||||||
cron = '0' + cron.substring(1, cron.length);
|
cron = '0' + cron.substring(1, cron.length);
|
||||||
}
|
}
|
||||||
const name = this.buildCronKey(pipelineId, trigger.id);
|
const triggerId = trigger.id;
|
||||||
|
const name = this.buildCronKey(pipelineId, triggerId);
|
||||||
this.cron.remove(name);
|
this.cron.remove(name);
|
||||||
this.cron.register({
|
this.cron.register({
|
||||||
name,
|
name,
|
||||||
cron,
|
cron,
|
||||||
job: async () => {
|
job: async () => {
|
||||||
logger.info('定时任务触发:', pipelineId, trigger.id);
|
logger.info('定时任务触发:', pipelineId, triggerId);
|
||||||
|
if (pipelineId == null) {
|
||||||
|
logger.warn('pipelineId为空,无法执行');
|
||||||
|
return;
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
await this.run(pipelineId, trigger.id);
|
await this.run(pipelineId, triggerId);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
logger.error('定时job执行失败:', e);
|
logger.error('定时job执行失败:', e);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue