removed dep methods
This commit is contained in:
parent
190b725149
commit
4d7c7df909
2 changed files with 20 additions and 96 deletions
|
|
@ -22,21 +22,24 @@ npm install @stock-bot/queue
|
||||||
### Basic Queue Setup
|
### Basic Queue Setup
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
import { QueueManager, providerRegistry } from '@stock-bot/queue';
|
import { QueueManager, handlerRegistry } from '@stock-bot/queue';
|
||||||
|
|
||||||
// Initialize queue manager
|
// Initialize queue manager (typically done via dependency injection)
|
||||||
const queueManager = new QueueManager({
|
const queueManager = new QueueManager({
|
||||||
queueName: 'my-service-queue',
|
|
||||||
workers: 5,
|
|
||||||
concurrency: 20,
|
|
||||||
redis: {
|
redis: {
|
||||||
host: 'localhost',
|
host: 'localhost',
|
||||||
port: 6379,
|
port: 6379,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
// Register providers
|
// Get or create a queue
|
||||||
providerRegistry.register('market-data', {
|
const queue = queueManager.getQueue('my-service-queue', {
|
||||||
|
workers: 5,
|
||||||
|
concurrency: 20,
|
||||||
|
});
|
||||||
|
|
||||||
|
// Register handlers
|
||||||
|
handlerRegistry.register('market-data', {
|
||||||
'fetch-price': async (payload) => {
|
'fetch-price': async (payload) => {
|
||||||
// Handle price fetching
|
// Handle price fetching
|
||||||
return { price: 100, symbol: payload.symbol };
|
return { price: 100, symbol: payload.symbol };
|
||||||
|
|
@ -47,8 +50,7 @@ providerRegistry.register('market-data', {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
// Initialize
|
// Queue is ready to use - no initialization needed
|
||||||
await queueManager.initialize();
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### Batch Processing
|
### Batch Processing
|
||||||
|
|
@ -242,8 +244,10 @@ If you're migrating from an existing queue implementation:
|
||||||
await queueService.initialize();
|
await queueService.initialize();
|
||||||
|
|
||||||
// After
|
// After
|
||||||
const queueManager = new QueueManager();
|
const queueManager = new QueueManager({
|
||||||
await queueManager.initialize();
|
redis: { host: 'localhost', port: 6379 }
|
||||||
|
});
|
||||||
|
// No initialization needed
|
||||||
```
|
```
|
||||||
|
|
||||||
3. **Update provider registration**:
|
3. **Update provider registration**:
|
||||||
|
|
@ -252,7 +256,7 @@ If you're migrating from an existing queue implementation:
|
||||||
providerRegistry.register('provider', config);
|
providerRegistry.register('provider', config);
|
||||||
|
|
||||||
// After
|
// After
|
||||||
queueManager.registerProvider('provider', config);
|
handlerRegistry.register('provider', config);
|
||||||
```
|
```
|
||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
|
|
@ -281,12 +285,14 @@ See the `/examples` directory for complete implementation examples:
|
||||||
|
|
||||||
4. **Clean up periodically**:
|
4. **Clean up periodically**:
|
||||||
```typescript
|
```typescript
|
||||||
await queueManager.clean(24 * 60 * 60 * 1000); // Clean jobs older than 24h
|
const queue = queueManager.getQueue('my-queue');
|
||||||
|
await queue.clean(24 * 60 * 60 * 1000); // Clean jobs older than 24h
|
||||||
```
|
```
|
||||||
|
|
||||||
5. **Monitor queue stats**:
|
5. **Monitor queue stats**:
|
||||||
```typescript
|
```typescript
|
||||||
const stats = await queueManager.getStats();
|
const queue = queueManager.getQueue('my-queue');
|
||||||
|
const stats = await queue.getStats();
|
||||||
console.log('Queue status:', stats);
|
console.log('Queue status:', stats);
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,6 @@ interface Logger {
|
||||||
* Main entry point for all queue operations with getQueue() method
|
* Main entry point for all queue operations with getQueue() method
|
||||||
*/
|
*/
|
||||||
export class QueueManager {
|
export class QueueManager {
|
||||||
private static instance: QueueManager | null = null;
|
|
||||||
private queues = new Map<string, Queue>();
|
private queues = new Map<string, Queue>();
|
||||||
private caches = new Map<string, CacheProvider>();
|
private caches = new Map<string, CacheProvider>();
|
||||||
private rateLimiter?: QueueRateLimiter;
|
private rateLimiter?: QueueRateLimiter;
|
||||||
|
|
@ -56,87 +55,6 @@ export class QueueManager {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @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 {
|
|
||||||
// Deprecated warning - using console since we don't have a logger instance
|
|
||||||
// eslint-disable-next-line no-console
|
|
||||||
console.warn(
|
|
||||||
'QueueManager.getInstance() is deprecated. Please use dependency injection instead.'
|
|
||||||
);
|
|
||||||
if (!QueueManager.instance) {
|
|
||||||
throw new Error('QueueManager not initialized. Call QueueManager.initialize(config) first.');
|
|
||||||
}
|
|
||||||
return QueueManager.instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @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 {
|
|
||||||
// Deprecated warning - using console since we don't have a logger instance
|
|
||||||
// eslint-disable-next-line no-console
|
|
||||||
console.warn(
|
|
||||||
'QueueManager.initialize() is deprecated. Please use dependency injection instead.'
|
|
||||||
);
|
|
||||||
if (QueueManager.instance) {
|
|
||||||
// eslint-disable-next-line no-console
|
|
||||||
console.warn('QueueManager already initialized, returning existing instance');
|
|
||||||
return QueueManager.instance;
|
|
||||||
}
|
|
||||||
QueueManager.instance = new QueueManager(config);
|
|
||||||
return QueueManager.instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @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 {
|
|
||||||
// Deprecated warning - using console since we don't have a logger instance
|
|
||||||
// eslint-disable-next-line no-console
|
|
||||||
console.warn(
|
|
||||||
'QueueManager.getOrInitialize() is deprecated. Please use dependency injection instead.'
|
|
||||||
);
|
|
||||||
if (QueueManager.instance) {
|
|
||||||
return QueueManager.instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!config) {
|
|
||||||
throw new Error(
|
|
||||||
'QueueManager not initialized and no config provided. ' +
|
|
||||||
'Either call initialize(config) first or provide config to getOrInitialize(config).'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return QueueManager.initialize(config);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated Use dependency injection instead. This method will be removed in a future version.
|
|
||||||
* Check if the QueueManager is initialized
|
|
||||||
*/
|
|
||||||
static isInitialized(): boolean {
|
|
||||||
return QueueManager.instance !== null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @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> {
|
|
||||||
if (QueueManager.instance) {
|
|
||||||
await QueueManager.instance.shutdown();
|
|
||||||
QueueManager.instance = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get or create a queue - unified method that handles both scenarios
|
* Get or create a queue - unified method that handles both scenarios
|
||||||
* This is the main method for accessing queues
|
* This is the main method for accessing queues
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue