tangled
alpha
login
or
join now
leaflet.pub
/
leaflet
291
fork
atom
a tool for shared writing and social publishing
291
fork
atom
overview
issues
28
pulls
pipelines
use top level pg connection and don't double clean up
awarm.space
6 months ago
a3f5a840
698c22a0
+7
-11
1 changed file
expand all
collapse all
unified
split
appview
index.ts
+7
-11
appview/index.ts
···
20
20
import { createIdentity } from "actions/createIdentity";
21
21
import { drizzle } from "drizzle-orm/node-postgres";
22
22
import { inngest } from "app/api/inngest/client";
23
23
-
import { Pool } from "pg";
23
23
+
import { Client } from "pg";
24
24
25
25
const cursorFile = process.env.CURSOR_FILE || "/cursor/cursor";
26
26
···
31
31
const QUOTE_PARAM = "/l-quote/";
32
32
async function main() {
33
33
let startCursor;
34
34
-
const pool = new Pool({
35
35
-
connectionString: process.env.DB_URL,
36
36
-
});
34
34
+
let client = new Client({ connectionString: process.env.DB_URL });
35
35
+
let db = drizzle(client);
37
36
try {
38
37
let file = (await readFile(cursorFile)).toString();
39
38
console.log("START CURSOR: " + file);
···
94
93
});
95
94
96
95
if (error && error.code === "23503") {
97
97
-
let c = await pool.connect();
98
98
-
let db = drizzle(c);
99
96
await createIdentity(db, { atp_did: evt.did });
100
100
-
c.release();
101
97
await supabase.from("publications").upsert({
102
98
uri: evt.uri.toString(),
103
99
identity_did: evt.did,
···
144
140
record: record.value as Json,
145
141
});
146
142
if (error && error.code === "23503") {
147
147
-
let c = await pool.connect();
148
148
-
let db = drizzle(c);
149
143
await createIdentity(db, { atp_did: evt.did });
150
150
-
c.release();
151
144
await supabase.from("publication_subscriptions").upsert({
152
145
uri: evt.uri.toString(),
153
146
identity: evt.did,
···
267
260
});
268
261
console.log("starting firehose consumer");
269
262
firehose.start();
263
263
+
let cleaningUp = false;
270
264
const cleanup = async () => {
265
265
+
if (cleaningUp) return;
266
266
+
cleaningUp = true;
271
267
console.log("shutting down firehose...");
272
272
-
pool.end();
268
268
+
client.end();
273
269
await firehose.destroy();
274
270
await runner.destroy();
275
271
process.exit();