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:
Lukas | AstroGD 2023-09-16 11:12:43 +02:00
parent f528d107da
commit d5b75b12c8
Signed by: AstroGD
GPG Key ID: 82A5E6C236C535AA
7 changed files with 765 additions and 369 deletions

View File

@ -2,7 +2,18 @@
This file is used to list changes made to this software. This file is used to list changes made to this software.
_Current development release: 1.1.0_ _Current development release: 1.1.1_
## V1.1.1 [2023-09-16]
### Updates
- Updated packages to latest versions
### Bugfixes
- Fixed a bug where the bot would crash on startup if the database connection establishment took too long
### Other
- Renamed db service in docker compose file from database to db
## V1.1.0 [2022-11-29] ## V1.1.0 [2022-11-29]

View File

@ -8,7 +8,7 @@ services:
tty: true tty: true
stdin_open: true stdin_open: true
depends_on: depends_on:
- database - db
restart: unless-stopped restart: unless-stopped
environment: environment:
- TOKEN=$TOKEN - TOKEN=$TOKEN
@ -16,7 +16,7 @@ services:
- DB_USERNAME=$DB_USERNAME - DB_USERNAME=$DB_USERNAME
- DB_PASSWORD=$DB_PASSWORD - DB_PASSWORD=$DB_PASSWORD
- DB_DATABASE=$DB_DATABASE - DB_DATABASE=$DB_DATABASE
database: db:
image: postgres:latest image: postgres:latest
restart: unless-stopped restart: unless-stopped
ports: ports:

1069
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
{ {
"name": "eu.astrogd.white-leopard", "name": "eu.astrogd.white-leopard",
"version": "1.1.0", "version": "1.1.1",
"description": "A Discord bot that checks channel names for blacklisted words and reverts the changes if necessary", "description": "A Discord bot that checks channel names for blacklisted words and reverts the changes if necessary",
"main": "build/index.js", "main": "build/index.js",
"scripts": { "scripts": {
@ -11,12 +11,12 @@
"deploy-commands:prod": "ts-node ci/deploy.ts", "deploy-commands:prod": "ts-node ci/deploy.ts",
"deploy:dev": "npm run build && npm run deploy-commands:dev && docker compose build && docker compose up -d", "deploy:dev": "npm run build && npm run deploy-commands:dev && docker compose build && docker compose up -d",
"deploy:prod": "rimraf build && npm run build && npm run deploy-commands:prod && docker build -t astrogd/white-leopard:latest . && docker push astrogd/white-leopard:latest", "deploy:prod": "rimraf build && npm run build && npm run deploy-commands:prod && docker build -t astrogd/white-leopard:latest . && docker push astrogd/white-leopard:latest",
"start": "npm run build && npm run deploy-commands:dev && docker-compose up --no-start && docker compose start database && node --enable-source-maps .", "start": "npm run build && npm run deploy-commands:dev && docker-compose up -d db && node --enable-source-maps .",
"migration:create": "node --require ts-node/register ./node_modules/typeorm/cli.js migration:generate -d src/data/dataSource.ts -p src/data/migrations/data", "migration:create": "node --require ts-node/register ./node_modules/typeorm/cli.js migration:generate -d src/data/dataSource.migration.ts -p src/data/migrations/data",
"migration:run": "node --require ts-node/register ./node_modules/typeorm/cli.js migration:run -d src/data/dataSource.ts", "migration:run": "node --require ts-node/register ./node_modules/typeorm/cli.js migration:run -d src/data/dataSource.migration.ts",
"migration:revert": "node --require ts-node/register ./node_modules/typeorm/cli.js migration:revert -d src/data/dataSource.ts", "migration:revert": "node --require ts-node/register ./node_modules/typeorm/cli.js migration:revert -d src/data/dataSource.migration.ts",
"migration:show": "node --require ts-node/register ./node_modules/typeorm/cli.js migration:show -d src/data/dataSource.ts", "migration:show": "node --require ts-node/register ./node_modules/typeorm/cli.js migration:show -d src/data/dataSource.migration.ts",
"migration:check": "node --require ts-node/register ./node_modules/typeorm/cli.js migration:generate --check -d src/data/dataSource.ts src/data/migrations/data" "migration:check": "node --require ts-node/register ./node_modules/typeorm/cli.js migration:generate --check -d src/data/dataSource.migration.ts src/data/migrations/data"
}, },
"repository": { "repository": {
"type": "git", "type": "git",
@ -30,15 +30,15 @@
"homepage": "https://github.com/r-Overwatch2/eu.astrogd.white-leopard#readme", "homepage": "https://github.com/r-Overwatch2/eu.astrogd.white-leopard#readme",
"devDependencies": { "devDependencies": {
"@types/express": "^4.17.14", "@types/express": "^4.17.14",
"@types/fs-extra": "^9.0.13", "@types/fs-extra": "^11.0.2",
"@types/node": "^18.11.9", "@types/node": "^18.17.17",
"rimraf": "^3.0.2", "rimraf": "^5.0.1",
"shx": "^0.3.4", "shx": "^0.3.4",
"ts-node": "^10.9.1", "ts-node": "^10.9.1",
"typescript": "^4.9.3" "typescript": "^5.2.2"
}, },
"dependencies": { "dependencies": {
"discord.js": "^14.6.0", "discord.js": "^14.13.0",
"dotenv": "^16.0.3", "dotenv": "^16.0.3",
"express": "^4.18.2", "express": "^4.18.2",
"fs-extra": "^11.0.0", "fs-extra": "^11.0.0",

View File

@ -1,13 +1,21 @@
import { runCleanup } from "../service"; import { runCleanup } from "../service";
import client from "./index"; import client from "./index";
import { initPromise } from "../data/dataSource";
const token = process.env["TOKEN"]; const token = process.env["TOKEN"];
if (!token) throw new ReferenceError("TOKEN environment variable is missing"); 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})`); console.log(`Connected to Discord API. Bot account is ${client.user?.tag} (${client.user?.id})`);
runCleanup(); 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" migrationsTransactionMode: "each"
}); });
dataSource.initialize(); const initPromise = dataSource.initialize();
export default dataSource; export default dataSource;
export {
initPromise
}