first refactor
This commit is contained in:
parent
1f5dac28c7
commit
588f666943
84 changed files with 996 additions and 1062 deletions
|
|
@ -3,6 +3,7 @@ import type { CacheProvider } from '@stock-bot/cache';
|
|||
import { createCache } from '@stock-bot/cache';
|
||||
import type { HandlerRegistry } from '@stock-bot/handler-registry';
|
||||
import { getLogger } from '@stock-bot/logger';
|
||||
import type { LoggerLike as Logger } from '@stock-bot/logger';
|
||||
import Redis from 'ioredis';
|
||||
import { Queue, type QueueWorkerConfig } from './queue';
|
||||
import { QueueRateLimiter } from './rate-limiter';
|
||||
|
|
@ -19,16 +20,6 @@ import type {
|
|||
} 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* QueueManager provides unified queue and cache management with service discovery
|
||||
* Handles both local and cross-service queue operations
|
||||
|
|
|
|||
|
|
@ -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
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@
|
|||
"references": [
|
||||
{ "path": "../cache" },
|
||||
{ "path": "../handler-registry" },
|
||||
{ "path": "../handlers" },
|
||||
{ "path": "../logger" },
|
||||
{ "path": "../types" }
|
||||
]
|
||||
|
|
|
|||
|
|
@ -2,8 +2,8 @@
|
|||
"extends": ["//"],
|
||||
"tasks": {
|
||||
"build": {
|
||||
"dependsOn": ["@stock-bot/cache#build", "@stock-bot/logger#build", "@stock-bot/types#build"],
|
||||
"outputs": ["dist/**"],
|
||||
"dependsOn": ["^build"],
|
||||
"outputs": ["dist/**", "*.tsbuildinfo"],
|
||||
"inputs": [
|
||||
"src/**",
|
||||
"package.json",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue