Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion front/next-env.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/// <reference types="next" />
/// <reference types="next/image-types/global" />
import "./.next/dev/types/routes.d.ts";
import "./.next/types/routes.d.ts";

// NOTE: This file should not be edited
// see https://nextjs.org/docs/app/api-reference/config/typescript for more information.
2 changes: 0 additions & 2 deletions functions/src/functions/arcgis-function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ export async function arcgisFunction(
context.error("arcgis-function: ERROR", error);
throw error;
} finally {
context.log("arcgis-function: disconnecting from database...");
await dbServer.disconnect();
context.log("arcgis-function: END");
}
}
Expand Down
3 changes: 0 additions & 3 deletions functions/src/functions/scraping-functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,8 @@ export async function scrapingsFunction(
context.error("scrapings-function: ERROR", error);
throw error;
} finally {
context.log("scrapings-function: disconnecting from database...");
await dbServer.disconnect();
context.log("scrapings-function: END");
}
await dbServer.disconnect();
}

app.timer("scrapings-function", {
Expand Down
20 changes: 13 additions & 7 deletions packages/db/src/core/servers/db.server.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
import { MongoClient, type Db } from "mongodb";

let client: MongoClient;
let client: MongoClient | null = null;

const connect = async (connectionURL: string) => {
client = new MongoClient(connectionURL, {
serverSelectionTimeoutMS: 5000,
connectTimeoutMS: 5000,
});
await client.connect();
if (!client) {
client = new MongoClient(connectionURL, {
serverSelectionTimeoutMS: 5000,
connectTimeoutMS: 5000,
});
await client.connect();
}
dbServer.db = client.db();
};

const disconnect = async () => {
await client.close();
if (client) {
await client.close();
client = null;
dbServer.db = undefined;
}
};

interface DBServer {
Expand Down