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:
@ -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();
|
3
src/data/dataSource.migration.ts
Normal file
3
src/data/dataSource.migration.ts
Normal file
@ -0,0 +1,3 @@
|
||||
import dataSource from "./dataSource";
|
||||
|
||||
export default dataSource;
|
@ -28,6 +28,9 @@ const dataSource = new DataSource({
|
||||
migrationsTransactionMode: "each"
|
||||
});
|
||||
|
||||
dataSource.initialize();
|
||||
const initPromise = dataSource.initialize();
|
||||
|
||||
export default dataSource;
|
||||
export default dataSource;
|
||||
export {
|
||||
initPromise
|
||||
}
|
Reference in New Issue
Block a user