running prettier for cleanup

This commit is contained in:
Boki 2025-06-11 10:13:25 -04:00
parent fe7733aeb5
commit d85cd58acd
151 changed files with 29158 additions and 27966 deletions

View file

@ -1,6 +1,6 @@
import Redis from 'ioredis';
import { getLogger } from '@stock-bot/logger';
import { dragonflyConfig } from '@stock-bot/config';
import { getLogger } from '@stock-bot/logger';
interface ConnectionConfig {
name: string;
@ -33,7 +33,7 @@ export class RedisConnectionManager {
*/
getConnection(config: ConnectionConfig): Redis {
const { name, singleton = false, db } = config;
if (singleton) {
// Use shared connection across all instances
if (!RedisConnectionManager.sharedConnections.has(name)) {
@ -66,7 +66,9 @@ export class RedisConnectionManager {
retryDelayOnFailover: dragonflyConfig.DRAGONFLY_RETRY_DELAY,
connectTimeout: dragonflyConfig.DRAGONFLY_CONNECT_TIMEOUT,
commandTimeout: dragonflyConfig.DRAGONFLY_COMMAND_TIMEOUT,
keepAlive: dragonflyConfig.DRAGONFLY_ENABLE_KEEPALIVE ? dragonflyConfig.DRAGONFLY_KEEPALIVE_INTERVAL * 1000 : 0,
keepAlive: dragonflyConfig.DRAGONFLY_ENABLE_KEEPALIVE
? dragonflyConfig.DRAGONFLY_KEEPALIVE_INTERVAL * 1000
: 0,
connectionName: name,
lazyConnect: false, // Connect immediately instead of waiting for first command
...(dragonflyConfig.DRAGONFLY_TLS && {
@ -90,7 +92,7 @@ export class RedisConnectionManager {
this.logger.info(`Redis connection ready: ${name}`);
});
redis.on('error', (err) => {
redis.on('error', err => {
this.logger.error(`Redis connection error for ${name}:`, err);
});
@ -121,7 +123,7 @@ export class RedisConnectionManager {
*/
async closeAllConnections(): Promise<void> {
// Close instance-specific connections
const instancePromises = Array.from(this.connections.values()).map(conn =>
const instancePromises = Array.from(this.connections.values()).map(conn =>
this.closeConnection(conn)
);
await Promise.all(instancePromises);
@ -129,8 +131,8 @@ export class RedisConnectionManager {
// Close shared connections (only if this is the last instance)
if (RedisConnectionManager.instance === this) {
const sharedPromises = Array.from(RedisConnectionManager.sharedConnections.values()).map(conn =>
this.closeConnection(conn)
const sharedPromises = Array.from(RedisConnectionManager.sharedConnections.values()).map(
conn => this.closeConnection(conn)
);
await Promise.all(sharedPromises);
RedisConnectionManager.sharedConnections.clear();
@ -145,7 +147,7 @@ export class RedisConnectionManager {
getConnectionCount(): { shared: number; unique: number } {
return {
shared: RedisConnectionManager.sharedConnections.size,
unique: this.connections.size
unique: this.connections.size,
};
}
@ -155,7 +157,7 @@ export class RedisConnectionManager {
getConnectionNames(): { shared: string[]; unique: string[] } {
return {
shared: Array.from(RedisConnectionManager.sharedConnections.keys()),
unique: Array.from(this.connections.keys())
unique: Array.from(this.connections.keys()),
};
}
@ -198,10 +200,7 @@ export class RedisConnectionManager {
*/
static async waitForAllConnections(timeout: number = 30000): Promise<void> {
const instance = this.getInstance();
const allConnections = new Map([
...instance.connections,
...this.sharedConnections
]);
const allConnections = new Map([...instance.connections, ...this.sharedConnections]);
if (allConnections.size === 0) {
instance.logger.info('No Redis connections to wait for');
@ -210,7 +209,7 @@ export class RedisConnectionManager {
instance.logger.info(`Waiting for ${allConnections.size} Redis connections to be ready...`);
const connectionPromises = Array.from(allConnections.entries()).map(([name, redis]) =>
const connectionPromises = Array.from(allConnections.entries()).map(([name, redis]) =>
instance.waitForConnection(redis, name, timeout)
);
@ -259,15 +258,12 @@ export class RedisConnectionManager {
*/
static areAllConnectionsReady(): boolean {
const instance = this.getInstance();
const allConnections = new Map([
...instance.connections,
...this.sharedConnections
]);
return allConnections.size > 0 &&
Array.from(allConnections.keys()).every(name =>
this.readyConnections.has(name)
);
const allConnections = new Map([...instance.connections, ...this.sharedConnections]);
return (
allConnections.size > 0 &&
Array.from(allConnections.keys()).every(name => this.readyConnections.has(name))
);
}
}