Fix(plugin workflow) (#549)
* fix(plugin-workflow): clear options when change collection * fix(plugin-workflow): fix schedule trigger
This commit is contained in:
parent
8fa4be8589
commit
95d0b524d0
@ -4,7 +4,7 @@ import { getApp, sleep } from '..';
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
describe.skip('workflow > triggers > schedule', () => {
|
describe('workflow > triggers > schedule', () => {
|
||||||
let app: Application;
|
let app: Application;
|
||||||
let db: Database;
|
let db: Database;
|
||||||
let PostRepo;
|
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' }});
|
const post = await PostRepo.create({ values: { title: 't1' }});
|
||||||
|
|
||||||
await sleep(1000);
|
await sleep(1000);
|
||||||
const executions = await workflow.getExecutions();
|
const executions = await workflow.getExecutions();
|
||||||
expect(executions.length).toBe(0);
|
expect(executions.length).toBe(0);
|
||||||
|
|
||||||
await sleep(1000);
|
await sleep(2000);
|
||||||
const [execution] = await workflow.getExecutions();
|
const [execution] = await workflow.getExecutions();
|
||||||
expect(execution).toBeDefined();
|
expect(execution).toBeDefined();
|
||||||
expect(execution.context.data.id).toBe(post.id);
|
expect(execution.context.data.id).toBe(post.id);
|
||||||
|
@ -62,8 +62,8 @@ ScheduleModes.set(SCHEDULE_MODE.CONSTANT, {
|
|||||||
trigger(workflow, date) {
|
trigger(workflow, date) {
|
||||||
const { startsOn, endsOn, repeat } = workflow.config;
|
const { startsOn, endsOn, repeat } = workflow.config;
|
||||||
if (startsOn && typeof repeat === 'number') {
|
if (startsOn && typeof repeat === 'number') {
|
||||||
const startTime = Date.parse(startsOn);
|
const startTime = Math.floor(Date.parse(startsOn) / 1000) * 1000;
|
||||||
if ((startTime - date.getTime()) % repeat) {
|
if (Math.round(date.getTime() - startTime) % repeat) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user