diff --git a/libStorage.js b/libStorage.js index e80c0b0..4c9a954 100644 --- a/libStorage.js +++ b/libStorage.js @@ -30,13 +30,12 @@ var Connection = mysql.createPool({ * @param {string} sqlQuery The SQL query string * @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 {object} params Hidden parameters - * @param {object} params.retry Retry value to increase retry time + * @param {number} _retry Set by error retry, increments the number a query has been retried to increase wait time and track a specific query */ function runSQL(sqlQuery, connection, callback = (err, rows) => { log.ERROR(err); throw err; -}, {retry = 0}) { +}, _retry = 0) { // Start the MySQL Connection if (!connection) connection = Connection; connection.query(sqlQuery, (err, rows) => { @@ -44,7 +43,7 @@ function runSQL(sqlQuery, connection, callback = (err, rows) => { if (err.code === "EHOSTUNREACH") { // DB Connection is unavailable let retryTimeout; - switch(retry){ + switch(_retry){ case 0: retryTimeout = 30000; break; @@ -58,7 +57,7 @@ function runSQL(sqlQuery, connection, callback = (err, rows) => { log.WARN(`Database connection is unavailable, waiting ${ retryTimeout / 1000 } seconds...`); retry += 1 // 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); }