mirror of
https://github.com/maierfelix/POGOserver.git
synced 2026-08-28 13:34:09 -05:00
Update
- Handle db errors and try to reconnect instead of crash
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "POGOServer",
|
||||
"version": "0.2.5",
|
||||
"version": "0.2.6",
|
||||
"description": "",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
||||
@@ -11,12 +11,18 @@ export function setupConnection() {
|
||||
if (error) {
|
||||
this.print(error, 31);
|
||||
this.retry("Retrying again in ", () => this.setupConnection().then(resolve), 5);
|
||||
return void 0;
|
||||
} else {
|
||||
this.db.instance = db;
|
||||
this.loadCollection(CFG.SERVER_MONGO_COLLECTION_USERS).then(() => {
|
||||
this.print(`\x1b[36;1mMongoDB\x1b[0m\x1b[32;1m connection established\x1b[0m`);
|
||||
resolve();
|
||||
});
|
||||
}
|
||||
db.on("close", (error) => {
|
||||
this.print(error, 31);
|
||||
this.retry("Trying to reconnect in ", () => this.setupConnection().then(resolve), 5);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -21,9 +21,14 @@ export function setupConnection() {
|
||||
}
|
||||
this.db.instance = connection;
|
||||
this.createTableIfNoExists().then(() => {
|
||||
this.print(`\x1b[36;1mMySQL\x1b[0m\x1b[32;1m connection established\x1b[0m`);
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
connection.on("error", (error) => {
|
||||
this.print(error, 31);
|
||||
this.retry("Trying to reconnect in ", () => this.setupConnection().then(resolve), 5);
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@@ -9,11 +9,6 @@ export function setup() {
|
||||
this.createAssetDownloadSession().then(() => {
|
||||
this.setupDatabaseConnection().then(() => {
|
||||
|
||||
let dbType = String(CFG.SERVER_USE_DATABASE).toLowerCase();
|
||||
let name = dbType === "mongo" ? "MongoDB" : "MySQL";
|
||||
|
||||
this.print(`\x1b[36;1m${name}\x1b[0m\x1b[${CFG.SERVER_DEFAULT_CONSOLE_COLOR};1m connection established\x1b[0m`);
|
||||
|
||||
if (CFG.SERVER_PORT < 1) {
|
||||
this.print("Invalid port!", 31);
|
||||
return void 0;
|
||||
|
||||
Reference in New Issue
Block a user