fix(plugin-workflow): fix interval number greater then 32-bits integer (#3592)
This commit is contained in:
parent
2140df071d
commit
7c79e58df9
@ -3,6 +3,8 @@ import parser from 'cron-parser';
|
|||||||
import type Plugin from '../../Plugin';
|
import type Plugin from '../../Plugin';
|
||||||
import { SCHEDULE_MODE, parseDateWithoutMs } from './utils';
|
import { SCHEDULE_MODE, parseDateWithoutMs } from './utils';
|
||||||
|
|
||||||
|
const MAX_SAFE_INTERVAL = 2147483647;
|
||||||
|
|
||||||
export default class StaticScheduleTrigger {
|
export default class StaticScheduleTrigger {
|
||||||
private timers: Map<string, NodeJS.Timeout | null> = new Map();
|
private timers: Map<string, NodeJS.Timeout | null> = new Map();
|
||||||
|
|
||||||
@ -80,7 +82,17 @@ export default class StaticScheduleTrigger {
|
|||||||
if (toggle) {
|
if (toggle) {
|
||||||
if (!this.timers.has(key)) {
|
if (!this.timers.has(key)) {
|
||||||
const interval = Math.max(nextTime - Date.now(), 0);
|
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 {
|
} else {
|
||||||
const timer = this.timers.get(key);
|
const timer = this.timers.get(key);
|
||||||
|
Loading…
Reference in New Issue
Block a user