Open History to see the last commit
1import { Pool } from "pg";
2import { attachDatabasePool } from "@neon/functions";
3import { parseTriggerDelivery } from "@neon/functions/triggers";
4import { runSession } from "../ingest/session";
5const pool = new Pool({
6 connectionString: process.env.DATABASE_URL,
7 max: 4,
8 connectionTimeoutMillis: 10000,
9 statement_timeout: 10000,
10});
11attachDatabasePool(pool);
12export default {
13 async fetch(request: Request) {
14 if (request.method !== "POST")
15 return new Response("Method not allowed", { status: 405 });
16 const delivery = await parseTriggerDelivery(request);
17 if (!delivery.ok || delivery.invocation.type !== "schedule")
18 return new Response("Verified schedule delivery required", {
19 status: 403,
20 });
21 try {
22 const result = await runSession(pool, {
23 owner: delivery.invocation.invocationId,
24 signal: request.signal,
25 budgetMs: Number(process.env.INGEST_REQUEST_BUDGET_MS ?? 240000),
26 tenureMs: Number(process.env.INGEST_TENURE_MS ?? 120000),
27 overlapMs: Number(process.env.INGEST_OVERLAP_MS ?? 90000),
28 smoothingMs: Number(process.env.INGEST_SMOOTHING_MS ?? 28000),
29 });
30 return Response.json(result);
31 } catch {
32 return Response.json(
33 {
34 error:
35 "Ingestion session ended; the next scheduled delivery will recover.",
36 },
37 { status: 503 },
38 );
39 }
40 },
41};