fix(plugin-workflow): fix off static schedule trigger (#3595)
* fix(plugin-workflow): fix off static schedule trigger * test(plugin-workflow): add test case
This commit is contained in:
parent
7c79e58df9
commit
41a8344be9
@ -218,6 +218,33 @@ describe('workflow > triggers > schedule > static mode', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('status', () => {
|
||||
it('should not trigger after turned off', async () => {
|
||||
const start = await sleepToEvenSecond();
|
||||
const future = new Date();
|
||||
future.setSeconds(future.getSeconds() + 2);
|
||||
|
||||
const workflow = await WorkflowModel.create({
|
||||
enabled: true,
|
||||
type: 'schedule',
|
||||
config: {
|
||||
mode: 0,
|
||||
startsOn: future.toISOString(),
|
||||
repeat: 1000,
|
||||
},
|
||||
});
|
||||
|
||||
await sleep(1000);
|
||||
|
||||
await workflow.update({ enabled: false });
|
||||
|
||||
await sleep(3000);
|
||||
|
||||
const executions = await workflow.getExecutions();
|
||||
expect(executions.length).toBe(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe('dispatch', () => {
|
||||
it('missed non-repeated scheduled time should not be triggered', async () => {
|
||||
await sleepToEvenSecond();
|
||||
|
@ -78,8 +78,8 @@ export default class StaticScheduleTrigger {
|
||||
}
|
||||
|
||||
schedule(workflow, nextTime, toggle = true) {
|
||||
const key = `${workflow.id}@${nextTime}`;
|
||||
if (toggle) {
|
||||
const key = `${workflow.id}@${nextTime}`;
|
||||
if (!this.timers.has(key)) {
|
||||
const interval = Math.max(nextTime - Date.now(), 0);
|
||||
if (interval > MAX_SAFE_INTERVAL) {
|
||||
@ -95,9 +95,12 @@ export default class StaticScheduleTrigger {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
const timer = this.timers.get(key);
|
||||
clearTimeout(timer);
|
||||
this.timers.delete(key);
|
||||
for (const [key, timer] of this.timers.entries()) {
|
||||
if (key.startsWith(`${workflow.id}@`)) {
|
||||
clearTimeout(timer);
|
||||
this.timers.delete(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user