import { runOrderItemsArchive, type ArchiveSummary, type ArchiveRunOptions } from '@/src/dbService' import { ensureWorkerInit } from '@/src/lib/worker-init' /** 2:00 AM IST (Cloudflare cron runs in UTC). */ export const CRON_ORDER_ITEMS_ARCHIVE = '30 20 * * *' export async function runOrderItemsArchiveCron(params: { cron: string env: any now?: Date }): Promise { const { cron, env, now } = params if (cron !== CRON_ORDER_ITEMS_ARCHIVE) { return null } ensureWorkerInit(env) return runOrderItemsArchive({ now }) } /** Guarded test/local entry point; the env is the worker's global ENV. */ export async function runOrderItemsArchiveNow(options: ArchiveRunOptions = {}): Promise { const env = (globalThis as { ENV?: Record }).ENV ensureWorkerInit(env as any) return runOrderItemsArchive(options) }