Fix(plugin workflow) (#549)

* fix(plugin-workflow): clear options when change collection

* fix(plugin-workflow): fix schedule trigger
This commit is contained in:
Junyi 2022-06-29 00:00:27 +08:00 committed by GitHub
parent 8fa4be8589
commit 95d0b524d0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 4 deletions

View File

@ -4,7 +4,7 @@ import { getApp, sleep } from '..';
describe.skip('workflow > triggers > schedule', () => {
describe('workflow > triggers > schedule', () => {
let app: Application;
let db: Database;
let PostRepo;
@ -186,13 +186,16 @@ describe.skip('workflow > triggers > schedule', () => {
}
});
const now = new Date();
await sleep((2.5 - now.getSeconds() % 2) * 1000 - now.getMilliseconds());
const post = await PostRepo.create({ values: { title: 't1' }});
await sleep(1000);
const executions = await workflow.getExecutions();
expect(executions.length).toBe(0);
await sleep(1000);
await sleep(2000);
const [execution] = await workflow.getExecutions();
expect(execution).toBeDefined();
expect(execution.context.data.id).toBe(post.id);

View File

@ -62,8 +62,8 @@ ScheduleModes.set(SCHEDULE_MODE.CONSTANT, {
trigger(workflow, date) {
const { startsOn, endsOn, repeat } = workflow.config;
if (startsOn && typeof repeat === 'number') {
const startTime = Date.parse(startsOn);
if ((startTime - date.getTime()) % repeat) {
const startTime = Math.floor(Date.parse(startsOn) / 1000) * 1000;
if (Math.round(date.getTime() - startTime) % repeat) {
return;
}
}