MCPcopy Index your code
hub / github.com/simstudioai/sim / calculateNextRunTime

Function calculateNextRunTime

apps/sim/background/schedule-execution.ts:580–603  ·  view source on GitHub ↗
(
  schedule: { cronExpression?: string; lastRanAt?: string },
  blocks: Record<string, BlockState>
)

Source from the content-addressed store, hash-verified

578}
579
580function 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
605export async function executeScheduleJob(payload: ScheduleExecutionPayload) {
606 const correlation = buildScheduleCorrelation(payload)

Callers

nothing calls this directly

Calls 2

getSubBlockValueFunction · 0.90
getScheduleTimeValuesFunction · 0.90

Tested by

no test coverage detected