freshyo/apps/backend/src/jobs/order-items-archive.ts
2026-10-20 16:13:09 +05:30

26 lines
883 B
TypeScript

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<ArchiveSummary | null> {
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<ArchiveSummary> {
const env = (globalThis as { ENV?: Record<string, unknown> }).ENV
ensureWorkerInit(env as any)
return runOrderItemsArchive(options)
}