Fixing declaration bug and updating comments
This commit is contained in:
@@ -30,13 +30,12 @@ var Connection = mysql.createPool({
|
|||||||
* @param {string} sqlQuery The SQL query string
|
* @param {string} sqlQuery The SQL query string
|
||||||
* @param {*} connection The SQL connection to be used to query
|
* @param {*} connection The SQL connection to be used to query
|
||||||
* @param {function} callback The callback function to be called with an error or the results
|
* @param {function} callback The callback function to be called with an error or the results
|
||||||
* @param {object} params Hidden parameters
|
* @param {number} _retry Set by error retry, increments the number a query has been retried to increase wait time and track a specific query
|
||||||
* @param {object} params.retry Retry value to increase retry time
|
|
||||||
*/
|
*/
|
||||||
function runSQL(sqlQuery, connection, callback = (err, rows) => {
|
function runSQL(sqlQuery, connection, callback = (err, rows) => {
|
||||||
log.ERROR(err);
|
log.ERROR(err);
|
||||||
throw err;
|
throw err;
|
||||||
}, {retry = 0}) {
|
}, _retry = 0) {
|
||||||
// Start the MySQL Connection
|
// Start the MySQL Connection
|
||||||
if (!connection) connection = Connection;
|
if (!connection) connection = Connection;
|
||||||
connection.query(sqlQuery, (err, rows) => {
|
connection.query(sqlQuery, (err, rows) => {
|
||||||
@@ -44,7 +43,7 @@ function runSQL(sqlQuery, connection, callback = (err, rows) => {
|
|||||||
if (err.code === "EHOSTUNREACH") {
|
if (err.code === "EHOSTUNREACH") {
|
||||||
// DB Connection is unavailable
|
// DB Connection is unavailable
|
||||||
let retryTimeout;
|
let retryTimeout;
|
||||||
switch(retry){
|
switch(_retry){
|
||||||
case 0:
|
case 0:
|
||||||
retryTimeout = 30000;
|
retryTimeout = 30000;
|
||||||
break;
|
break;
|
||||||
@@ -58,7 +57,7 @@ function runSQL(sqlQuery, connection, callback = (err, rows) => {
|
|||||||
log.WARN(`Database connection is unavailable, waiting ${ retryTimeout / 1000 } seconds...`);
|
log.WARN(`Database connection is unavailable, waiting ${ retryTimeout / 1000 } seconds...`);
|
||||||
retry += 1
|
retry += 1
|
||||||
// Wait for the retry timeout before trying the query again
|
// Wait for the retry timeout before trying the query again
|
||||||
setTimeout(runSQL(sqlQuery, connection, callback, { retry: retry }));
|
setTimeout(runSQL(sqlQuery, connection, callback, _retry));
|
||||||
}
|
}
|
||||||
else return callback(err, undefined);
|
else return callback(err, undefined);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user