Skip to content

Commit 33b1639

Browse files
committed
Update cron route configuration for monthly sync and Next.js App Router
1 parent 8323904 commit 33b1639

File tree

2 files changed

+20
-20
lines changed

2 files changed

+20
-20
lines changed

client/src/app/api/cron/route.ts

+12-20
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,18 @@
1-
import { NextRequest, NextResponse } from "next/server";
2-
3-
export const config = {
4-
runtime: "edge",
5-
regions: ["iad1"], // specify a single region
6-
};
7-
8-
// This defines a schedule for running once a week (Sunday at 00:00 UTC)
9-
export const dynamic = "force-dynamic";
10-
export const revalidate = 0;
11-
12-
// Set the cron schedule to run monthly (1st day of each month at midnight)
13-
export const maxDuration = 300; // 5 minute maximum duration
14-
export const schedule = { cron: "0 0 1 * *" }; // Monthly at midnight on the 1st day
15-
16-
export async function GET(request: NextRequest) {
1+
import { NextResponse } from "next/server";
2+
3+
/**
4+
* This route is called by Vercel Cron Jobs
5+
* Cron configuration is set in vercel.json at the project root
6+
* Schedule: Monthly at midnight on the 1st day of each month
7+
*/
8+
export async function GET() {
179
try {
1810
const secretKey = process.env.SYNC_SECRET_KEY || "your-default-secret-key";
1911

2012
// Call our sync API
2113
const syncResponse = await fetch(
2214
`${
23-
process.env.NEXT_PUBLIC_BASE_URL || request.nextUrl.origin
15+
process.env.NEXT_PUBLIC_BASE_URL || "https://your-app-url.com"
2416
}/api/syncAllProfiles?secretKey=${secretKey}`,
2517
{ method: "GET" }
2618
);
@@ -30,19 +22,19 @@ export async function GET(request: NextRequest) {
3022
if (!result.success) {
3123
console.error("Sync failed:", result);
3224
return NextResponse.json(
33-
{ message: "Weekly sync failed", error: result },
25+
{ message: "Monthly sync failed", error: result },
3426
{ status: 500 }
3527
);
3628
}
3729

3830
return NextResponse.json({
39-
message: "Weekly sync completed successfully",
31+
message: "Monthly sync completed successfully",
4032
result,
4133
});
4234
} catch (error) {
4335
console.error("Error during scheduled sync:", error);
4436
return NextResponse.json(
45-
{ message: "Error during weekly sync", error },
37+
{ message: "Error during monthly sync", error },
4638
{ status: 500 }
4739
);
4840
}

vercel.json

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"crons": [
3+
{
4+
"path": "/api/cron",
5+
"schedule": "0 0 1 * *"
6+
}
7+
]
8+
}

0 commit comments

Comments
 (0)