conditionally load message broker
This commit is contained in:
parent
8078e07b9a
commit
4ac0e9a084
@ -1,4 +1,5 @@
|
||||
import { LoggerClientOptions } from '@navy.gif/logger';
|
||||
import { BrokerOptions } from '@navy.gif/wrappers';
|
||||
|
||||
export type FileExtensions = 'mp4' | 'png' | 'mkv' | 'mov' | 'wmv' | 'm4v' | 'webm' | 'gif' | 'jpg' | 'exe' | 'avi' | 'webp' | 'jpeg' | 'htm' | 'zip' | 'txt';
|
||||
export type FileType = 'video' | 'image' | 'audio' | 'text' | 'application' | 'message' | 'multipart';
|
||||
@ -34,7 +35,8 @@ type MongoDBOptions = {
|
||||
|
||||
export type DatabaseOptions = {
|
||||
mariadb: MariaDBOptions,
|
||||
mongodb: MongoDBOptions
|
||||
mongodb: MongoDBOptions,
|
||||
broker: BrokerOptions
|
||||
}
|
||||
|
||||
export type SignupCode = {
|
||||
|
@ -47,7 +47,8 @@ export type ServerOptions = {
|
||||
http: HttpOptions,
|
||||
databases: {
|
||||
mariadb?: MariaOptions,
|
||||
mongodb?: MongoOptions
|
||||
mongodb?: MongoOptions,
|
||||
broker?: BrokerOptions
|
||||
},
|
||||
logger?: LoggerClientOptions,
|
||||
domain: string,
|
||||
@ -59,8 +60,7 @@ export type ServerOptions = {
|
||||
discord: {
|
||||
scope?: string[],
|
||||
version?: number
|
||||
},
|
||||
rabbitConfig: BrokerOptions
|
||||
}
|
||||
}
|
||||
|
||||
export type Permissions = {
|
||||
|
@ -61,6 +61,9 @@
|
||||
"broadcastLevel": 3
|
||||
},
|
||||
"databases": {
|
||||
"messageBroker": {
|
||||
"load": false
|
||||
},
|
||||
"mariadb": {
|
||||
"load": false,
|
||||
"client": {
|
||||
|
@ -15,7 +15,7 @@
|
||||
"@navy.gif/commandparser": "^1.5.2",
|
||||
"@navy.gif/logger": "^2.3.3",
|
||||
"@navy.gif/passport-discord": "^0.2.2-b",
|
||||
"@navy.gif/wrappers": "^1.3.18",
|
||||
"@navy.gif/wrappers": "^1.3.20",
|
||||
"@types/cors": "^2.8.13",
|
||||
"@types/express-fileupload": "^1.4.1",
|
||||
"@types/express-session": "^1.17.7",
|
||||
@ -51,7 +51,6 @@
|
||||
"nodemon": "^2.0.20"
|
||||
},
|
||||
"scripts": {
|
||||
"setup": "yarn install --registry https://registry.corgi.wtf",
|
||||
"start": "yarn build && node build/index.js",
|
||||
"build": "tsc",
|
||||
"lint": "eslint src/ --fix",
|
||||
|
@ -18,7 +18,6 @@ import { ControllerOptions } from '../../@types/Controller.js';
|
||||
import BaseCommand from './BaseCommand.js';
|
||||
import { IPCMessage } from '../../@types/Other.js';
|
||||
import { ServerOptions } from '../../@types/Server.js';
|
||||
import { BrokerOptions } from '@navy.gif/wrappers';
|
||||
|
||||
const CLIOptions: CommandOption[] = [
|
||||
new CommandOption({
|
||||
@ -191,12 +190,11 @@ class Controller extends EventEmitter {
|
||||
serverOptions = {} as ServerOptions,
|
||||
logger = {},
|
||||
discord = {},
|
||||
databases = {},
|
||||
rabbitConfig = {} as BrokerOptions
|
||||
databases = {}
|
||||
} = this.#_options;
|
||||
return {
|
||||
serverOptions: {
|
||||
...serverOptions, logger, discord, databases, rabbitConfig
|
||||
...serverOptions, logger, discord, databases
|
||||
},
|
||||
...shardOptions,
|
||||
env: this.#_options.env,
|
||||
|
@ -57,7 +57,7 @@ class Server extends EventEmitter {
|
||||
#_mongodb: MongoDB;
|
||||
#_memoryStoreProvider: MongoMemory;
|
||||
#_userDatabase: UserDatabaseInterface;
|
||||
#_messageBroker: MessageBroker;
|
||||
#_messageBroker?: MessageBroker;
|
||||
|
||||
#_rateLimiter: RateLimiter;
|
||||
#_authenticator: Authenticator;
|
||||
@ -79,7 +79,7 @@ class Server extends EventEmitter {
|
||||
MONGO_MEMORY_PASS, MONGO_MEMORY_DB, MONGO_MEMORY_AUTH_DB,
|
||||
RABBIT_HOST, RABBIT_USER, RABBIT_PASS, RABBIT_VHOST, RABBIT_PORT
|
||||
} = process.env as { [key: string]: string };
|
||||
const { http: httpOpts, databases, name, rabbitConfig } = options;
|
||||
const { http: httpOpts, databases, name } = options;
|
||||
|
||||
// This key never leaves memory and is exclusively used on the server, the salt can stay static
|
||||
const encryption = Util.createEncryptionKey(CRYPTO_SECRET as string, CRYPTO_SALT as string);
|
||||
@ -151,8 +151,9 @@ class Server extends EventEmitter {
|
||||
});
|
||||
this.#_userDatabase = new UserDatabase(this, this.#_mongodb);
|
||||
|
||||
if (databases.broker?.load)
|
||||
this.#_messageBroker = new MessageBroker(this, {
|
||||
...rabbitConfig,
|
||||
...databases.broker,
|
||||
host: RABBIT_HOST,
|
||||
user: RABBIT_USER,
|
||||
pass: RABBIT_PASS,
|
||||
@ -239,7 +240,7 @@ class Server extends EventEmitter {
|
||||
|
||||
await this.#_userDatabase.init();
|
||||
|
||||
await this.#_messageBroker.init();
|
||||
await this.#_messageBroker?.init();
|
||||
|
||||
await this.#_flagManager.init();
|
||||
|
||||
@ -299,7 +300,7 @@ class Server extends EventEmitter {
|
||||
await this.#_mongodb.close();
|
||||
await this.#_mariadb.close();
|
||||
await this.#_memoryStoreProvider.close();
|
||||
await this.#_messageBroker.close();
|
||||
await this.#_messageBroker?.close();
|
||||
this.#logger.status('DB shutdowns complete.');
|
||||
|
||||
this.#logger.status('Server shutdown complete.');
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { MongoDB, ObjectId } from "@navy.gif/wrappers";
|
||||
import { MessageBroker, MongoDB, ObjectId } from "@navy.gif/wrappers";
|
||||
import Server from "../Server.js";
|
||||
import Flag from "../structures/Flag.js";
|
||||
import { FlagConsumer, FlagData, FlagEnv } from "../../../@types/Flags.js";
|
||||
@ -20,7 +20,7 @@ class FlagManager {
|
||||
#mongo: MongoDB;
|
||||
#collectionName = 'flags';
|
||||
#flags: Collection<string, Flag>;
|
||||
#broker;
|
||||
#broker?: MessageBroker;
|
||||
#logger: LoggerClient;
|
||||
#_tags: string[];
|
||||
|
||||
@ -50,7 +50,7 @@ class FlagManager {
|
||||
}
|
||||
|
||||
this.#_tags = [ ...tags ];
|
||||
this.#broker.subscribe('flagUpdates', this.#flagUpdate.bind(this));
|
||||
this.#broker?.subscribe('flagUpdates', this.#flagUpdate.bind(this));
|
||||
|
||||
}
|
||||
|
||||
@ -117,7 +117,7 @@ class FlagManager {
|
||||
const flag = new Flag(this, data);
|
||||
await this.#mongo.insertOne(this.#collectionName, flag.json);
|
||||
this.#flags.set(flag.id, flag);
|
||||
this.#broker.publish('flagUpdates', { origin: this.#server.shardId, flag: flag.json });
|
||||
this.#broker?.publish('flagUpdates', { origin: this.#server.shardId, flag: flag.json });
|
||||
return flag;
|
||||
|
||||
}
|
||||
@ -127,7 +127,7 @@ class FlagManager {
|
||||
const json = flag.json as { _id?: string };
|
||||
delete json._id;
|
||||
await this.#mongo.updateOne(this.#collectionName, { _id: flag.id }, json, true);
|
||||
this.#broker.publish('flagUpdates', { origin: this.#server.shardId, flag: flag.json });
|
||||
this.#broker?.publish('flagUpdates', { origin: this.#server.shardId, flag: flag.json });
|
||||
|
||||
}
|
||||
|
||||
|
10
yarn.lock
10
yarn.lock
@ -1773,15 +1773,15 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@navy.gif/wrappers@npm:^1.3.18":
|
||||
version: 1.3.18
|
||||
resolution: "@navy.gif/wrappers@npm:1.3.18"
|
||||
"@navy.gif/wrappers@npm:^1.3.20":
|
||||
version: 1.3.20
|
||||
resolution: "@navy.gif/wrappers@npm:1.3.20"
|
||||
dependencies:
|
||||
amqp-connection-manager: ^4.1.12
|
||||
amqplib: ^0.10.3
|
||||
mongodb: ^5.2.0
|
||||
mysql: ^2.18.1
|
||||
checksum: fadee6eb5b17da6c876aa2e34cedd8048e0993eb409835f106365d8eccd0645d79593b018da29e61567a0b70c93824439148de4bc4e9ae84a068fae96a4e641f
|
||||
checksum: 5fa76d7e9fc84cf9b2790905a8703bedeb541f3b5f0cb43de002ea4e531eae05d1d31a5c0f674692cc2ad0ec96b8ee6994ef91bda50d4dc45dc2375304886e24
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
@ -7038,7 +7038,7 @@ __metadata:
|
||||
"@navy.gif/commandparser": ^1.5.2
|
||||
"@navy.gif/logger": ^2.3.3
|
||||
"@navy.gif/passport-discord": ^0.2.2-b
|
||||
"@navy.gif/wrappers": ^1.3.18
|
||||
"@navy.gif/wrappers": ^1.3.20
|
||||
"@types/cors": ^2.8.13
|
||||
"@types/express-fileupload": ^1.4.1
|
||||
"@types/express-session": ^1.17.7
|
||||
|
Loading…
Reference in New Issue
Block a user