Advertisement
Guest User

Untitled

a guest
Jun 27th, 2019
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.94 KB | None | 0 0
  1. function sqlReconnect() {
  2. var con = mysql.createConnection({
  3. host: config.mysqlHost,
  4. user: config.mysqlUser,
  5. password: config.mysqlPassword,
  6. database: config.database
  7. });
  8.  
  9. con.connect((err) => {
  10. if(err) {
  11. console.error(date.logDate("Could not connect to MySQL database, attempting to reconnect..."));
  12. setTimeout(sqlReconnect, 3000);
  13. return;
  14. } else {
  15. console.log(date.logDate("Connection successful"));
  16.  
  17. // the checkWhiteList function sends an SQL query every 10 second
  18. setInterval(() => {checkWhiteList(con)}, 10000);
  19. }
  20. });
  21.  
  22. con.on("error", (err) => {
  23. if(err.code === "PROTOCOL_CONNECTION_LOST") {
  24. console.log(date.logDate("Connection to MySQL database was lost, reconnecting..."));
  25. sqlReconnect();
  26. return;
  27. } else {
  28. console.log(date.logDate("There was a MySQL error: " + err));
  29. }
  30. });
  31. }
  32.  
  33. // client is the discord client
  34. client.on("ready", () => {
  35. console.log(date.logDate("Bot online"));
  36.  
  37. sqlReconnect();
  38. });
  39.  
  40. [2019-04-20 10:05:36] Bot online
  41. [2019-04-20 10:05:36] Connection successful
  42. [2019-04-20 10:06:04] Connection to MySQL database was lost, reconnecting...
  43. [2019-04-20 10:06:04] Could not connect to MySQL database, attempting to reconnect...
  44. .../index.js:14
  45. if (err) throw err;
  46. ^
  47.  
  48. Error: Cannot enqueue Query after fatal error.
  49. at Protocol._validateEnqueue (.../node_modules/mysql/lib/protocol/Protocol.js:212:16)
  50. at Protocol._enqueue (.../node_modules/mysql/lib/protocol/Protocol.js:138:13)
  51. at Connection.query (.../node_modules/mysql/lib/Connection.js:201:25)
  52. at checkWhiteList (.../index.js:13:9)
  53. at Timeout.setInterval [as _onTimeout] (.../index.js:70:24)
  54. at ontimeout (timers.js:466:11)
  55. at tryOnTimeout (timers.js:304:5)
  56. at Timer.listOnTimeout (timers.js:267:5)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement