Set db connection to UTC - Fix hashrate indexing

This commit is contained in:
nymkappa
2022-03-12 14:47:33 +01:00
parent ae10622d8e
commit c601f92732
10 changed files with 86 additions and 68 deletions

View File

@@ -1,5 +1,5 @@
import config from './config';
import { createPool } from 'mysql2/promise';
import { createPool, PoolConnection } from 'mysql2/promise';
import logger from './logger';
export class DB {
@@ -11,13 +11,24 @@ export class DB {
password: config.DATABASE.PASSWORD,
connectionLimit: 10,
supportBigNumbers: true,
timezone: '+00:00',
});
static connectionsReady: number[] = [];
static async getConnection() {
const connection: PoolConnection = await DB.pool.getConnection();
const connectionId = connection['connection'].connectionId;
if (!DB.connectionsReady.includes(connectionId)) {
await connection.query(`SET time_zone='+00:00';`);
this.connectionsReady.push(connectionId);
}
return connection;
}
}
export async function checkDbConnection() {
try {
const connection = await DB.pool.getConnection();
const connection = await DB.getConnection();
logger.info('Database connection established.');
connection.release();
} catch (e) {