Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function sqlReconnect() {
- var con = mysql.createConnection({
- host: config.mysqlHost,
- user: config.mysqlUser,
- password: config.mysqlPassword,
- database: config.database
- });
- con.connect((err) => {
- if(err) {
- console.error(date.logDate("Could not connect to MySQL database, attempting to reconnect..."));
- setTimeout(sqlReconnect, 3000);
- return;
- } else {
- console.log(date.logDate("Connection successful"));
- // the checkWhiteList function sends an SQL query every 10 second
- setInterval(() => {checkWhiteList(con)}, 10000);
- }
- });
- con.on("error", (err) => {
- if(err.code === "PROTOCOL_CONNECTION_LOST") {
- console.log(date.logDate("Connection to MySQL database was lost, reconnecting..."));
- sqlReconnect();
- return;
- } else {
- console.log(date.logDate("There was a MySQL error: " + err));
- }
- });
- }
- // client is the discord client
- client.on("ready", () => {
- console.log(date.logDate("Bot online"));
- sqlReconnect();
- });
- [2019-04-20 10:05:36] Bot online
- [2019-04-20 10:05:36] Connection successful
- [2019-04-20 10:06:04] Connection to MySQL database was lost, reconnecting...
- [2019-04-20 10:06:04] Could not connect to MySQL database, attempting to reconnect...
- .../index.js:14
- if (err) throw err;
- ^
- Error: Cannot enqueue Query after fatal error.
- at Protocol._validateEnqueue (.../node_modules/mysql/lib/protocol/Protocol.js:212:16)
- at Protocol._enqueue (.../node_modules/mysql/lib/protocol/Protocol.js:138:13)
- at Connection.query (.../node_modules/mysql/lib/Connection.js:201:25)
- at checkWhiteList (.../index.js:13:9)
- at Timeout.setInterval [as _onTimeout] (.../index.js:70:24)
- at ontimeout (timers.js:466:11)
- at tryOnTimeout (timers.js:304:5)
- at Timer.listOnTimeout (timers.js:267:5)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement