- node-cron scheduler runs at 00:00 UTC every day - Custom server.js auto-starts cron on npm start - isRunning lock prevents concurrent report runs - cron-initialize API for manual cron control - Updated npm start to use server.js entry point
18 lines
426 B
TypeScript
18 lines
426 B
TypeScript
import { NextResponse } from "next/server";
|
|
import { startDailyReportCron } from "@/lib/daily-report-cron";
|
|
|
|
export const runtime = "nodejs";
|
|
|
|
// Guard: only start cron once per server instance
|
|
let started = false;
|
|
|
|
export async function GET() {
|
|
if (started) {
|
|
return NextResponse.json({ status: "already_started" });
|
|
}
|
|
started = true;
|
|
|
|
startDailyReportCron();
|
|
return NextResponse.json({ status: "started" });
|
|
}
|