removed singletop pattern from queue manager

This commit is contained in:
Boki 2025-06-22 19:16:25 -04:00
parent eeb5d1aca2
commit db3aa9c330
12 changed files with 504 additions and 380 deletions

View file

@ -15,7 +15,7 @@ import { getRedisConnection } from './utils';
const logger = getLogger('queue-manager');
/**
* Singleton QueueManager that provides unified queue and cache management
* QueueManager provides unified queue and cache management
* Main entry point for all queue operations with getQueue() method
*/
export class QueueManager {
@ -28,7 +28,7 @@ export class QueueManager {
private shutdownPromise: Promise<void> | null = null;
private config: QueueManagerConfig;
private constructor(config: QueueManagerConfig) {
constructor(config: QueueManagerConfig) {
this.config = config;
this.redisConnection = getRedisConnection(config.redis);
@ -42,16 +42,20 @@ export class QueueManager {
});
}
logger.info('QueueManager singleton initialized', {
logger.info('QueueManager initialized', {
redis: `${config.redis.host}:${config.redis.port}`,
});
}
/**
* @deprecated Use dependency injection instead. This method will be removed in a future version.
* Get the singleton instance
* @throws Error if not initialized - use initialize() first
*/
static getInstance(): QueueManager {
logger.warn(
'QueueManager.getInstance() is deprecated. Please use dependency injection instead.'
);
if (!QueueManager.instance) {
throw new Error('QueueManager not initialized. Call QueueManager.initialize(config) first.');
}
@ -59,10 +63,14 @@ export class QueueManager {
}
/**
* @deprecated Use dependency injection instead. This method will be removed in a future version.
* Initialize the singleton with config
* Must be called before getInstance()
*/
static initialize(config: QueueManagerConfig): QueueManager {
logger.warn(
'QueueManager.initialize() is deprecated. Please use dependency injection instead.'
);
if (QueueManager.instance) {
logger.warn('QueueManager already initialized, returning existing instance');
return QueueManager.instance;
@ -72,10 +80,14 @@ export class QueueManager {
}
/**
* @deprecated Use dependency injection instead. This method will be removed in a future version.
* Get or initialize the singleton
* Convenience method that combines initialize and getInstance
*/
static getOrInitialize(config?: QueueManagerConfig): QueueManager {
logger.warn(
'QueueManager.getOrInitialize() is deprecated. Please use dependency injection instead.'
);
if (QueueManager.instance) {
return QueueManager.instance;
}
@ -91,6 +103,7 @@ export class QueueManager {
}
/**
* @deprecated Use dependency injection instead. This method will be removed in a future version.
* Check if the QueueManager is initialized
*/
static isInitialized(): boolean {
@ -98,6 +111,7 @@ export class QueueManager {
}
/**
* @deprecated Use dependency injection instead. This method will be removed in a future version.
* Reset the singleton (mainly for testing)
*/
static async reset(): Promise<void> {
@ -489,4 +503,4 @@ export class QueueManager {
getConfig(): Readonly<QueueManagerConfig> {
return { ...this.config };
}
}
}