Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions src/helpers/mysql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import Pool from 'mysql/lib/Pool';
import log from './log';

const connectionLimit = parseInt(process.env.CONNECTION_LIMIT || '25');
export const QUERY_TIMEOUT_MS = 3e4; // 30 seconds

log.info(`[mysql] connection limit ${connectionLimit}`);

// @ts-ignore
Expand All @@ -17,7 +19,6 @@ hubConfig.host = hubConfig.hosts[0].name;
hubConfig.port = hubConfig.hosts[0].port;
hubConfig.connectTimeout = 60e3;
hubConfig.acquireTimeout = 60e3;
hubConfig.timeout = 60e3;
hubConfig.charset = 'utf8mb4';
hubConfig.ssl = { rejectUnauthorized: true };

Expand All @@ -32,14 +33,31 @@ sequencerConfig.host = sequencerConfig.hosts[0].name;
sequencerConfig.port = sequencerConfig.hosts[0].port;
sequencerConfig.connectTimeout = 60e3;
sequencerConfig.acquireTimeout = 60e3;
sequencerConfig.timeout = 60e3;
sequencerConfig.charset = 'utf8mb4';
sequencerConfig.ssl = { rejectUnauthorized: true };

const sequencerDB = mysql.createPool(sequencerConfig);

bluebird.promisifyAll([Pool, Connection]);

const originalQueryAsync = hubDB.queryAsync;
hubDB.queryAsync = function (sql: string, values?: any) {
return originalQueryAsync.call(this, {
sql: sql,
values: values,
timeout: QUERY_TIMEOUT_MS
});
};
Comment on lines +43 to +50
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't you simplify like this?

Suggested change
const originalQueryAsync = hubDB.queryAsync;
hubDB.queryAsync = function (sql: string, values?: any) {
return originalQueryAsync.call(this, {
sql: sql,
values: values,
timeout: QUERY_TIMEOUT_MS
});
};
hubDB.queryAsync = (sql: string, values?: any) => hubDB.queryAsync.call(this, {
sql,
values,
timeout: QUERY_TIMEOUT_MS
});

Copy link
Member

@bonustrack bonustrack Aug 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That may break the this actually. But dont need to repeat sql and values, or doing a const for queryAsync


const originalSequencerQueryAsync = sequencerDB.queryAsync;
sequencerDB.queryAsync = function (sql: string, values?: any) {
return originalSequencerQueryAsync.call(this, {
sql: sql,
values: values,
timeout: QUERY_TIMEOUT_MS
});
};

export const closeDatabase = (): Promise<void> => {
return new Promise(resolve => {
hubDB.end(() => {
Expand Down
Loading