diff --git a/packages/plugins/workflow/src/__tests__/triggers/schedule.test.ts b/packages/plugins/workflow/src/__tests__/triggers/schedule.test.ts index c0149aee7..4fa292f65 100644 --- a/packages/plugins/workflow/src/__tests__/triggers/schedule.test.ts +++ b/packages/plugins/workflow/src/__tests__/triggers/schedule.test.ts @@ -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); diff --git a/packages/plugins/workflow/src/triggers/schedule.ts b/packages/plugins/workflow/src/triggers/schedule.ts index 4d870668b..6ff579c8c 100644 --- a/packages/plugins/workflow/src/triggers/schedule.ts +++ b/packages/plugins/workflow/src/triggers/schedule.ts @@ -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; } }