Skip to content

Commit 126c151

Browse files
authored
Merge pull request #101 from marcodejongh/fix_shared_sync_3
Split up shared sync into seperate crons
2 parents bfad313 + 15b8e1b commit 126c151

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

app/api/internal/shared-sync/route.ts renamed to app/api/internal/shared-sync/[board_name]/route.ts

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,29 @@
11
// app/api/cron/sync-shared-data/route.ts
22
import { NextResponse } from 'next/server';
33
import { syncSharedData } from '@/lib/data-sync/aurora/shared-sync';
4+
import { BoardRouteParameters, ParsedBoardRouteParameters } from '@/app/lib/types';
5+
import { parseBoardRouteParams } from '@/app/lib/url-utils';
46

57
export const dynamic = 'force-dynamic';
68
export const maxDuration = 300;
79
// This is a simple way to secure the endpoint, should be replaced with a better solution
810
const CRON_SECRET = process.env.CRON_SECRET;
911

10-
export async function GET(request: Request) {
12+
export async function GET(request: Request, { params }: { params: BoardRouteParameters }) {
13+
const { board_name }: ParsedBoardRouteParameters = parseBoardRouteParams(params);
14+
1115
try {
1216
// Basic auth check
1317
const authHeader = request.headers.get('authorization');
1418
if (process.env.VERCEL_ENV !== 'development' && authHeader !== `Bearer ${CRON_SECRET}`) {
1519
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
1620
}
1721

18-
// Sync both board types
19-
const results = await Promise.all([
20-
syncSharedData('tension'),
21-
syncSharedData('kilter')
22-
]);
22+
const result = syncSharedData(board_name);
2323

2424
return NextResponse.json({
2525
success: true,
26-
results: {
27-
tension: results[0],
28-
kilter: results[1],
29-
},
26+
results: result,
3027
});
3128
} catch (error) {
3229
console.error('Cron job failed:', error);

vercel.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@
22
"installCommand": "npm install --legacy-peer-deps",
33
"crons": [
44
{
5-
"path": "/api/internal/shared-sync",
5+
"path": "/api/internal/shared-sync/tension",
66
"schedule": "0 */2 * * *"
7+
},
8+
{
9+
"path": "/api/internal/shared-sync/kilter",
10+
"schedule": "15 */2 * * *"
711
}
812
]
913
}

0 commit comments

Comments
 (0)