- Handle db errors and try to reconnect instead of crash
This commit is contained in:
Felix
2016-08-16 22:46:33 +02:00
parent 9e18c1e808
commit f4558676a6
4 changed files with 12 additions and 6 deletions

View File

@@ -1,6 +1,6 @@
{
"name": "POGOServer",
"version": "0.2.5",
"version": "0.2.6",
"description": "",
"repository": {
"type": "git",

View File

@@ -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);
});
});
});

View File

@@ -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);
});
});
}

View File

@@ -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;