From 15b8e1ba96a3c3471d977a15767a0e5c6f037d76 Mon Sep 17 00:00:00 2001 From: Marco de Jongh <1107647+marcodejongh@users.noreply.github.com> Date: Mon, 30 Dec 2024 16:15:58 +1100 Subject: [PATCH] Split up shared sync into seperate crons --- .../shared-sync/{ => [board_name]}/route.ts | 17 +++++++---------- vercel.json | 6 +++++- 2 files changed, 12 insertions(+), 11 deletions(-) rename app/api/internal/shared-sync/{ => [board_name]}/route.ts (68%) diff --git a/app/api/internal/shared-sync/route.ts b/app/api/internal/shared-sync/[board_name]/route.ts similarity index 68% rename from app/api/internal/shared-sync/route.ts rename to app/api/internal/shared-sync/[board_name]/route.ts index 7b6e35a1..41f3b8a7 100644 --- a/app/api/internal/shared-sync/route.ts +++ b/app/api/internal/shared-sync/[board_name]/route.ts @@ -1,13 +1,17 @@ // app/api/cron/sync-shared-data/route.ts import { NextResponse } from 'next/server'; import { syncSharedData } from '@/lib/data-sync/aurora/shared-sync'; +import { BoardRouteParameters, ParsedBoardRouteParameters } from '@/app/lib/types'; +import { parseBoardRouteParams } from '@/app/lib/url-utils'; export const dynamic = 'force-dynamic'; export const maxDuration = 300; // This is a simple way to secure the endpoint, should be replaced with a better solution const CRON_SECRET = process.env.CRON_SECRET; -export async function GET(request: Request) { +export async function GET(request: Request, { params }: { params: BoardRouteParameters }) { + const { board_name }: ParsedBoardRouteParameters = parseBoardRouteParams(params); + try { // Basic auth check const authHeader = request.headers.get('authorization'); @@ -15,18 +19,11 @@ export async function GET(request: Request) { return NextResponse.json({ error: 'Unauthorized' }, { status: 401 }); } - // Sync both board types - const results = await Promise.all([ - syncSharedData('tension'), - syncSharedData('kilter') - ]); + const result = syncSharedData(board_name); return NextResponse.json({ success: true, - results: { - tension: results[0], - kilter: results[1], - }, + results: result, }); } catch (error) { console.error('Cron job failed:', error); diff --git a/vercel.json b/vercel.json index 0da3b15e..c0e2ebf4 100644 --- a/vercel.json +++ b/vercel.json @@ -2,8 +2,12 @@ "installCommand": "npm install --legacy-peer-deps", "crons": [ { - "path": "/api/internal/shared-sync", + "path": "/api/internal/shared-sync/tension", "schedule": "0 */2 * * *" + }, + { + "path": "/api/internal/shared-sync/kilter", + "schedule": "15 */2 * * *" } ] }