first refactor
This commit is contained in:
parent
1f5dac28c7
commit
588f666943
84 changed files with 996 additions and 1062 deletions
|
|
@ -1,19 +1,10 @@
|
|||
import { Queue as BullQueue, QueueEvents, Worker, type Job } from 'bullmq';
|
||||
import type { LoggerLike as Logger } from '@stock-bot/logger';
|
||||
// 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
|
||||
interface Logger {
|
||||
info(message: string, meta?: Record<string, unknown>): void;
|
||||
error(message: string, meta?: Record<string, unknown>): void;
|
||||
warn(message: string, meta?: Record<string, unknown>): void;
|
||||
debug(message: string, meta?: Record<string, unknown>): void;
|
||||
trace(message: string, meta?: Record<string, unknown>): void;
|
||||
child?(name: string, context?: Record<string, unknown>): Logger;
|
||||
}
|
||||
|
||||
export interface QueueWorkerConfig {
|
||||
workers?: number;
|
||||
concurrency?: number;
|
||||
|
|
@ -205,6 +196,17 @@ export class Queue {
|
|||
return await this.bullQueue.getJob(jobId);
|
||||
}
|
||||
|
||||
/** Wait for a result using a QueueEvents connection owned by this queue. */
|
||||
async waitForJob<T>(job: Job<unknown, T>, timeout = 30000): Promise<T> {
|
||||
if (!this.queueEvents) {
|
||||
this.queueEvents = new QueueEvents(this.queueName, {
|
||||
connection: getRedisConnection(this.redisConfig),
|
||||
});
|
||||
}
|
||||
await this.queueEvents.waitUntilReady();
|
||||
return job.waitUntilFinished(this.queueEvents, timeout);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get jobs by state
|
||||
*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue