From 1705b10b989530cd1748fade384179757338fe01 Mon Sep 17 00:00:00 2001 From: Junyi Date: Mon, 20 Feb 2023 21:48:15 +0800 Subject: [PATCH] fix(plugin-workflow): fix schedule trigger number type repeat (#1475) --- .../workflow/src/server/triggers/schedule.ts | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/packages/plugins/workflow/src/server/triggers/schedule.ts b/packages/plugins/workflow/src/server/triggers/schedule.ts index 845eb4675..37058e1c8 100644 --- a/packages/plugins/workflow/src/server/triggers/schedule.ts +++ b/packages/plugins/workflow/src/server/triggers/schedule.ts @@ -51,11 +51,11 @@ ScheduleModes.set(SCHEDULE_MODE.CONSTANT, { } if (repeat) { - if (typeof repeat === 'number' - && repeat > this.cacheCycle - && (timestamp - startTime) % repeat > this.cacheCycle - ) { - return false; + if (typeof repeat === 'number') { + const next = timestamp - (timestamp - startTime) % repeat + repeat; + if (next <= timestamp || next > timestamp + this.cacheCycle) { + return false; + } } if (endsOn) { @@ -77,7 +77,6 @@ ScheduleModes.set(SCHEDULE_MODE.CONSTANT, { const timestamp = now.getTime(); // NOTE: align to second start const startTime = parseDateWithoutMs(startsOn); - if (!startTime || startTime > timestamp) { return; } @@ -498,7 +497,7 @@ export default class ScheduleTrigger extends Trigger { const should = await this.shouldCache(workflow, now); if (should) { - console.log('caching schedule workflow:', workflow.id); + this.plugin.app.logger.info('caching scheduled workflow will run in next minute:', workflow.id); } this.setCache(workflow, !should);