Fix process shutdown issues

This commit is contained in:
Zaid Abdulla committed 2019-09-23 16:03:08 -07:00
1 parent 4bcee572f1
commit ed0aa8ae7a
9 files changed
+63 -44

No files matched your search

+4 -4
View File
@@ -22,16 +22,16 @@ import * as config from "./config";
const MAX_CACHE_TTL = +config.get("MAX_CACHE_TTL");
let mongoClient: MongoClient;
let clientPromise: Promise<MongoClient>;
let mongoCollection: Collection;
let mongoTimeOffset = 0;
export async function connect(): Promise<void> {
const MONGODB_CONNECTION_URL = "" + config.get("MONGODB_CONNECTION_URL");
mongoClient = await MongoClient.connect(MONGODB_CONNECTION_URL, {
clientPromise = MongoClient.connect(MONGODB_CONNECTION_URL, {
useNewUrlParser: true
});
const db = mongoClient.db();
const db = (await clientPromise).db();
mongoCollection = db.collection("cache");
await mongoCollection.createIndex({ expire: 1 }, { expireAfterSeconds: 0 });
const now = Date.now();
@@ -40,7 +40,7 @@ export async function connect(): Promise<void> {
}
export async function disconnect(): Promise<void> {
if (mongoClient) await mongoClient.close();
if (clientPromise) await (await clientPromise).close();
}
export async function get(key): Promise<any> {