| 1 | import { eq } from "drizzle-orm"; |
| 2 | import { Cron } |
| 3 | import { db } |
| 4 | import { schedules } |
| 5 | |
| 6 | export function computeNextRun( |
| 7 | cronSecond: string, |
| 8 | cronMinute: string, |
| 9 | cronHour: string, |
| 10 | cronDayOfMonth: string, |
| 11 | cronDayOfWeek: string, |
| 12 | ): Date | |
| 13 | try { |
| 14 | const expr = |
| 15 | const cron = |
| 16 | return cron.nextRun |
| 17 | } catch { |
| 18 | return null; |
| 19 | } |
| 20 | } |
| 21 | |
| 22 | export async function completeSchedule |
| 23 | const schedule = |
| 24 | where: eq(schedules |
| 25 | }); |
| 26 | if (!schedule) |
| 27 | |
| 28 | const nextRunAt = |
| 29 | schedule.cronSecond, |
| 30 | schedule.cronMinute, |
| 31 | schedule.cronHour, |
| 32 | schedule.cronDayOfMonth, |
| 33 | schedule.cronDayOfWeek, |
| 34 | ); |
| 35 | |
| 36 | await db |
| 37 | .update(schedules) |
| 38 | .set({ |
| 39 | isProcessing: false, |
| 40 | lastRunAt: new Date |
| 41 | nextRunAt: nextRunAt ?? |
| 42 | }) |
| 43 | .where(eq(schedules |
| 44 | } |