(
schedule: { cronExpression?: string; lastRanAt?: string },
blocks: Record<string, BlockState>
)
| 578 | } |
| 579 | |
| 580 | function calculateNextRunTime( |
| 581 | schedule: { cronExpression?: string; lastRanAt?: string }, |
| 582 | blocks: Record<string, BlockState> |
| 583 | ): Date { |
| 584 | const scheduleBlock = Object.values(blocks).find( |
| 585 | (block) => block.type === 'starter' || block.type === 'schedule' |
| 586 | ) |
| 587 | if (!scheduleBlock) throw new Error('No starter or schedule block found') |
| 588 | const scheduleType = getSubBlockValue(scheduleBlock, 'scheduleType') |
| 589 | const scheduleValues = getScheduleTimeValues(scheduleBlock) |
| 590 | |
| 591 | const timezone = scheduleValues.timezone || 'UTC' |
| 592 | |
| 593 | if (schedule.cronExpression) { |
| 594 | const cron = new Cron(schedule.cronExpression, { |
| 595 | timezone, |
| 596 | }) |
| 597 | const nextDate = cron.nextRun() |
| 598 | if (!nextDate) throw new Error('Invalid cron expression or no future occurrences') |
| 599 | return nextDate |
| 600 | } |
| 601 | |
| 602 | return calculateNextTime(scheduleType, scheduleValues) |
| 603 | } |
| 604 | |
| 605 | export async function executeScheduleJob(payload: ScheduleExecutionPayload) { |
| 606 | const correlation = buildScheduleCorrelation(payload) |
nothing calls this directly
no test coverage detected