From 7c79e58df9fe89b50a60d9c8ab6eb8cc6d783b13 Mon Sep 17 00:00:00 2001 From: Junyi Date: Fri, 1 Mar 2024 17:49:45 +0800 Subject: [PATCH] fix(plugin-workflow): fix interval number greater then 32-bits integer (#3592) --- .../ScheduleTrigger/StaticScheduleTrigger.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/packages/plugins/@nocobase/plugin-workflow/src/server/triggers/ScheduleTrigger/StaticScheduleTrigger.ts b/packages/plugins/@nocobase/plugin-workflow/src/server/triggers/ScheduleTrigger/StaticScheduleTrigger.ts index 3fd4ff72b..966aa3a34 100644 --- a/packages/plugins/@nocobase/plugin-workflow/src/server/triggers/ScheduleTrigger/StaticScheduleTrigger.ts +++ b/packages/plugins/@nocobase/plugin-workflow/src/server/triggers/ScheduleTrigger/StaticScheduleTrigger.ts @@ -3,6 +3,8 @@ import parser from 'cron-parser'; import type Plugin from '../../Plugin'; import { SCHEDULE_MODE, parseDateWithoutMs } from './utils'; +const MAX_SAFE_INTERVAL = 2147483647; + export default class StaticScheduleTrigger { private timers: Map = new Map(); @@ -80,7 +82,17 @@ export default class StaticScheduleTrigger { if (toggle) { if (!this.timers.has(key)) { const interval = Math.max(nextTime - Date.now(), 0); - this.timers.set(key, setTimeout(this.trigger.bind(this, workflow, nextTime), interval)); + if (interval > MAX_SAFE_INTERVAL) { + this.timers.set( + key, + setTimeout(() => { + this.timers.delete(key); + this.schedule(workflow, nextTime); + }, MAX_SAFE_INTERVAL), + ); + } else { + this.timers.set(key, setTimeout(this.trigger.bind(this, workflow, nextTime), interval)); + } } } else { const timer = this.timers.get(key);