T-7: M0.3a — Harden dev Mongo safety: env-safety throws on unsafe data-pipeline QA reads, scheduled jobs default off, read-only bypass tests
This commit is contained in:
parent
0e5ebbd62f
commit
75e459f50b
11 changed files with 485 additions and 90 deletions
|
|
@ -1,5 +1,5 @@
|
|||
import { Queue as BullQueue, type Job } from 'bullmq';
|
||||
import Redis from 'ioredis';
|
||||
import Redis, { type RedisOptions } from 'ioredis';
|
||||
import type { CacheProvider } from '@stock-bot/cache';
|
||||
import { createCache } from '@stock-bot/cache';
|
||||
import type { HandlerRegistry } from '@stock-bot/handler-registry';
|
||||
|
|
@ -22,9 +22,21 @@ import type {
|
|||
QueueRoute,
|
||||
QueueStats,
|
||||
RateLimitRule,
|
||||
RedisConfig,
|
||||
} from './types';
|
||||
import { getRedisConnection } from './utils';
|
||||
|
||||
export interface QueueManagerDependencies {
|
||||
createRedis?: (options: RedisOptions) => Redis;
|
||||
createQueue?: (
|
||||
name: string,
|
||||
redisConfig: RedisConfig,
|
||||
defaultJobOptions: JobOptions,
|
||||
workerConfig: QueueWorkerConfig,
|
||||
logger: Logger
|
||||
) => Queue;
|
||||
}
|
||||
|
||||
/**
|
||||
* QueueManager provides unified queue and cache management with service discovery
|
||||
* Handles both local and cross-service queue operations
|
||||
|
|
@ -40,6 +52,7 @@ export class QueueManager {
|
|||
private shutdownPromise: Promise<void> | null = null;
|
||||
private config: QueueManagerConfig;
|
||||
private readonly logger: Logger;
|
||||
private readonly deps?: QueueManagerDependencies;
|
||||
|
||||
// Service discovery features
|
||||
private serviceName?: string;
|
||||
|
|
@ -47,7 +60,12 @@ export class QueueManager {
|
|||
private producerQueues = new Map<string, BullQueue>(); // For cross-service sending
|
||||
private handlerRegistry?: HandlerRegistry;
|
||||
|
||||
constructor(config: QueueManagerConfig, handlerRegistry?: HandlerRegistry, logger?: Logger) {
|
||||
constructor(
|
||||
config: QueueManagerConfig,
|
||||
handlerRegistry?: HandlerRegistry,
|
||||
logger?: Logger,
|
||||
deps?: QueueManagerDependencies
|
||||
) {
|
||||
// Always use DB 0 for queues if service name is provided
|
||||
if (config.serviceName) {
|
||||
config = {
|
||||
|
|
@ -63,11 +81,12 @@ export class QueueManager {
|
|||
this.serviceName = config.serviceName;
|
||||
this.handlerRegistry = handlerRegistry;
|
||||
this.logger = logger || getLogger('QueueManager');
|
||||
this.deps = deps;
|
||||
this.redisConnection = getRedisConnection(config.redis);
|
||||
|
||||
// Create ioredis connection for rate limiter
|
||||
const retryDelay = config.redis.retryDelay;
|
||||
this.ioredisConnection = new Redis({
|
||||
const ioredisOptions = {
|
||||
host: config.redis.host,
|
||||
port: config.redis.port,
|
||||
password: config.redis.password,
|
||||
|
|
@ -76,7 +95,10 @@ export class QueueManager {
|
|||
maxRetriesPerRequest: config.redis.maxRetriesPerRequest ?? 3,
|
||||
...(retryDelay === undefined ? {} : { retryStrategy: () => retryDelay }),
|
||||
enableReadyCheck: true,
|
||||
});
|
||||
};
|
||||
this.ioredisConnection = deps?.createRedis
|
||||
? deps.createRedis(ioredisOptions)
|
||||
: new Redis(ioredisOptions);
|
||||
|
||||
// Rate limiter will be initialized when rules are added dynamically
|
||||
// No longer initialized from config
|
||||
|
|
@ -167,13 +189,21 @@ export class QueueManager {
|
|||
queueManager: this,
|
||||
};
|
||||
|
||||
const queue = new Queue(
|
||||
queueName,
|
||||
this.config.redis,
|
||||
mergedOptions.defaultJobOptions || {},
|
||||
queueConfig,
|
||||
this.logger
|
||||
);
|
||||
const queue = this.deps?.createQueue
|
||||
? this.deps.createQueue(
|
||||
queueName,
|
||||
this.config.redis,
|
||||
mergedOptions.defaultJobOptions || {},
|
||||
queueConfig,
|
||||
this.logger
|
||||
)
|
||||
: new Queue(
|
||||
queueName,
|
||||
this.config.redis,
|
||||
mergedOptions.defaultJobOptions || {},
|
||||
queueConfig,
|
||||
this.logger
|
||||
);
|
||||
|
||||
// Store the queue
|
||||
this.queues.set(queueName, queue);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue