huge refactor to remove depenencie hell and add typesafe container
This commit is contained in:
parent
28b9822d55
commit
843a7b9b9b
148 changed files with 3603 additions and 2378 deletions
|
|
@ -1,6 +1,7 @@
|
|||
import { Queue as BullQueue, QueueEvents, Worker, type Job } from 'bullmq';
|
||||
import { handlerRegistry } from '@stock-bot/handlers';
|
||||
import type { JobData, JobOptions, ExtendedJobOptions, QueueStats, RedisConfig } from './types';
|
||||
// Handler registry will be injected
|
||||
import type { HandlerRegistry } from '@stock-bot/handler-registry';
|
||||
import type { ExtendedJobOptions, JobData, JobOptions, QueueStats, RedisConfig } from './types';
|
||||
import { getRedisConnection } from './utils';
|
||||
|
||||
// Logger interface for type safety
|
||||
|
|
@ -17,6 +18,7 @@ export interface QueueWorkerConfig {
|
|||
workers?: number;
|
||||
concurrency?: number;
|
||||
startWorker?: boolean;
|
||||
handlerRegistry?: HandlerRegistry;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -30,6 +32,7 @@ export class Queue {
|
|||
private queueName: string;
|
||||
private redisConfig: RedisConfig;
|
||||
private readonly logger: Logger;
|
||||
private readonly handlerRegistry?: HandlerRegistry;
|
||||
|
||||
constructor(
|
||||
queueName: string,
|
||||
|
|
@ -41,6 +44,7 @@ export class Queue {
|
|||
this.queueName = queueName;
|
||||
this.redisConfig = redisConfig;
|
||||
this.logger = logger || console;
|
||||
this.handlerRegistry = config.handlerRegistry;
|
||||
|
||||
const connection = getRedisConnection(redisConfig);
|
||||
|
||||
|
|
@ -338,7 +342,10 @@ export class Queue {
|
|||
|
||||
try {
|
||||
// Look up handler in registry
|
||||
const jobHandler = handlerRegistry.getOperation(handler, operation);
|
||||
if (!this.handlerRegistry) {
|
||||
throw new Error('Handler registry not configured for worker processing');
|
||||
}
|
||||
const jobHandler = this.handlerRegistry.getOperation(handler, operation);
|
||||
|
||||
if (!jobHandler) {
|
||||
throw new Error(`No handler found for ${handler}:${operation}`);
|
||||
|
|
@ -390,5 +397,4 @@ export class Queue {
|
|||
getWorkerCount(): number {
|
||||
return this.workers.length;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue