Fix db race condition

- Fixed a bug where the bot would crash if the db connection took too long
- Updated packages to latest version
- Bumped version to 1.1.1
This commit is contained in:
2023-09-16 11:12:43 +02:00
parent f528d107da
commit d5b75b12c8
7 changed files with 765 additions and 369 deletions

View File

@ -1,13 +1,21 @@
import { runCleanup } from "../service";
import client from "./index";
import { initPromise } from "../data/dataSource";
const token = process.env["TOKEN"];
if (!token) throw new ReferenceError("TOKEN environment variable is missing");
client.login(token);
async function run() {
console.log("Establishing database connection");
await initPromise;
console.log("Connection established\nAuthenticating with Discord API");
client.login(token);
}
client.on("ready", () => {
client.on("ready", async () => {
console.log(`Connected to Discord API. Bot account is ${client.user?.tag} (${client.user?.id})`);
runCleanup();
});
});
run();

View File

@ -0,0 +1,3 @@
import dataSource from "./dataSource";
export default dataSource;

View File

@ -28,6 +28,9 @@ const dataSource = new DataSource({
migrationsTransactionMode: "each"
});
dataSource.initialize();
const initPromise = dataSource.initialize();
export default dataSource;
export default dataSource;
export {
initPromise
}