Skip to content

Commit 507ca30

Browse files
feat: sync nightly crawl
1 parent e63a658 commit 507ca30

2 files changed

Lines changed: 36 additions & 0 deletions

File tree

.github/workflows/nightly-crawl.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,6 @@ jobs:
2828
GITHUB_TOKEN: ${{ secrets.DIRECTORY_GITHUB_TOKEN }}
2929
GITHUB_REPO: ArcedeDev/open-402
3030
CONCURRENCY: '15'
31+
SYNC_WEBHOOK_SECRET: ${{ secrets.SYNC_WEBHOOK_SECRET }}
32+
SYNC_WEBHOOK_URL: ${{ secrets.SYNC_WEBHOOK_URL }}
3133
run: npx tsx scripts/crawl.ts

scripts/crawl.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -759,6 +759,40 @@ async function main(): Promise<void> {
759759
log("ERROR: Failed to commit snapshot.json.");
760760
process.exit(1);
761761
}
762+
763+
// 10. Notify web app to sync snapshot → Supabase (fire-and-forget)
764+
const webhookSecret = process.env.SYNC_WEBHOOK_SECRET;
765+
const webhookUrl =
766+
process.env.SYNC_WEBHOOK_URL ||
767+
"https://agentinternetruntime.com/api/directory/sync";
768+
if (webhookSecret) {
769+
try {
770+
const syncRes = await fetch(webhookUrl, {
771+
method: "POST",
772+
headers: {
773+
Authorization: `Bearer ${webhookSecret}`,
774+
"Content-Type": "application/json",
775+
},
776+
body: JSON.stringify({
777+
triggered_by: "nightly-crawl",
778+
timestamp: new Date().toISOString(),
779+
}),
780+
signal: AbortSignal.timeout(30_000),
781+
});
782+
const syncData = (await syncRes.json().catch(() => ({}))) as Record<string, unknown>;
783+
if (syncRes.ok) {
784+
log(
785+
`[sync] OK: ${syncData.synced ?? 0} synced, ${syncData.skipped ?? 0} skipped, ${syncData.errors ?? 0} errors`
786+
);
787+
} else {
788+
log(
789+
`[sync] FAILED (${syncRes.status}): ${syncData.error ?? "unknown error"}`
790+
);
791+
}
792+
} catch (e) {
793+
log(`[sync] Webhook failed (non-fatal): ${e}`);
794+
}
795+
}
762796
}
763797

764798
main().catch((e) => {

0 commit comments

Comments
 (0)