Skip to content

Commit

Permalink
[feature] Added mysql timeouts to config
Browse files Browse the repository at this point in the history
  • Loading branch information
DrToldme committed Jun 4, 2024
1 parent 92682e7 commit aebdccb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
5 changes: 4 additions & 1 deletion Common/config/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,10 @@
"idleTimeoutMillis": 30000
}
},
"mysqlExtraOptions": {}
"mysqlExtraOptions": {
"connectTimeout": 60000,
"queryTimeout": 60000
}
},
"redis": {
"name": "redis",
Expand Down
7 changes: 6 additions & 1 deletion DocService/sources/databaseConnectors/mysqlConnector.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ const connectionConfiguration = {

const additionalOptions = configSql.get('mysqlExtraOptions');
const configuration = Object.assign({}, connectionConfiguration, additionalOptions);
let queryTimeout = 60000;
if (configuration.queryTimeout) {
queryTimeout = configuration.queryTimeout;
delete configuration.queryTimeout;
}

let pool = mysql.createPool(configuration);

Expand All @@ -68,7 +73,7 @@ async function executeQuery(ctx, sqlCommand, values = [], noModifyRes = false, n
try {
connection = await pool.getConnection();

const result = await connection.query(sqlCommand, values);
const result = await connection.query({ sql: sqlCommand, timeout: queryTimeout, values });

let output;
if (!noModifyRes) {
Expand Down

0 comments on commit aebdccb

Please sign in to comment.