removing deprecations

This commit is contained in:
Boki 2025-06-24 15:32:56 -04:00
parent fa67d666dc
commit f6038d385f
21 changed files with 91 additions and 158 deletions

View file

@ -305,18 +305,18 @@ export class RedisCache implements CacheProvider {
return null;
}
this.updateStats(true);
try {
const parsed = JSON.parse(value);
this.logger.debug('Cache raw get hit', { key });
return parsed;
} catch (error) {
// If JSON parsing fails, log the error with more context
this.logger.warn('Cache getRaw JSON parse failed', {
key,
this.logger.warn('Cache getRaw JSON parse failed', {
key,
valueLength: value.length,
valuePreview: value.substring(0, 100),
error: error instanceof Error ? error.message : String(error)
error: error instanceof Error ? error.message : String(error),
});
// Return the raw value as-is if it can't be parsed
return value as unknown as T;

View file

@ -4,7 +4,6 @@ import { join } from 'path';
import { parseArgs } from 'util';
import { redactSecrets } from './utils/secrets';
import {
checkDeprecations,
checkRequiredEnvVars,
formatValidationResult,
validateCompleteness,
@ -24,11 +23,6 @@ interface CliOptions {
help?: boolean;
}
const DEPRECATIONS = {
'service.legacyMode': 'Use service.mode instead',
'database.redis': 'Use database.dragonfly instead',
};
const REQUIRED_PATHS = [
'service.name',
'service.port',
@ -149,18 +143,6 @@ async function main() {
console.log(formatValidationResult(pathResult));
console.log();
// Deprecations
console.log('4. Deprecation Warnings:');
const warnings = checkDeprecations(config, DEPRECATIONS);
if (warnings && warnings.length > 0) {
for (const warning of warnings) {
console.log(` ⚠️ ${warning.path}: ${warning.message}`);
}
} else {
console.log(' ✅ No deprecated options found');
}
console.log();
// Overall result
const allValid = schemaResult.valid && envResult.valid && pathResult.valid;

View file

@ -37,40 +37,6 @@ export function validateConfig<T>(config: unknown, schema: z.ZodSchema<T>): Vali
}
}
/**
* Check for deprecated configuration options
*/
export function checkDeprecations(
config: Record<string, unknown>,
deprecations: Record<string, string>
): ValidationResult['warnings'] {
const warnings: ValidationResult['warnings'] = [];
function checkObject(obj: Record<string, unknown>, path: string[] = []): void {
for (const [key, value] of Object.entries(obj)) {
const currentPath = [...path, key];
const pathStr = currentPath.join('.');
if (pathStr in deprecations) {
const deprecationMessage = deprecations[pathStr];
if (deprecationMessage) {
warnings?.push({
path: pathStr,
message: deprecationMessage,
});
}
}
if (value && typeof value === 'object' && !Array.isArray(value)) {
checkObject(value as Record<string, unknown>, currentPath);
}
}
}
checkObject(config);
return warnings;
}
/**
* Check for required environment variables
*/

View file

@ -6,7 +6,7 @@ import type { MongoDBClient } from '@stock-bot/mongodb';
import type { PostgreSQLClient } from '@stock-bot/postgres';
import type { ProxyManager } from '@stock-bot/proxy';
import type { QuestDBClient } from '@stock-bot/questdb';
import type { SmartQueueManager } from '@stock-bot/queue';
import type { QueueManager } from '@stock-bot/queue';
import type { IServiceContainer } from '@stock-bot/types';
import type { AppConfig } from '../config/schemas';
import type { HandlerScanner } from '../scanner';
@ -25,7 +25,7 @@ export interface ServiceDefinitions {
globalCache: CacheProvider | null;
proxyManager: ProxyManager | null;
browser: Browser;
queueManager: SmartQueueManager | null;
queueManager: QueueManager | null;
// Database clients
mongoClient: MongoDBClient | null;

View file

@ -61,7 +61,7 @@ export function registerApplicationServices(
if (config.queue?.enabled && config.redis.enabled) {
container.register({
queueManager: asFunction(({ logger, handlerRegistry }) => {
const { SmartQueueManager } = require('@stock-bot/queue');
const { QueueManager } = require('@stock-bot/queue');
const queueConfig = {
serviceName: config.service?.serviceName || config.service?.name || 'unknown',
redis: {
@ -79,7 +79,7 @@ export function registerApplicationServices(
delayWorkerStart: config.queue!.delayWorkerStart ?? true, // Changed to true so ServiceApplication can start workers
autoDiscoverHandlers: true,
};
return new SmartQueueManager(queueConfig, handlerRegistry, logger);
return new QueueManager(queueConfig, handlerRegistry, logger);
}).singleton(),
});
} else {

View file

@ -3,7 +3,7 @@
* Discovers and registers handlers with the DI container
*/
import { asClass, asFunction, type AwilixContainer } from 'awilix';
import { asFunction, type AwilixContainer } from 'awilix';
import { glob } from 'glob';
import type {
HandlerConfiguration,
@ -82,7 +82,7 @@ export class HandlerScanner {
* Check if an exported value is a handler
*/
private isHandler(exported: any): boolean {
if (typeof exported !== 'function') return false;
if (typeof exported !== 'function') {return false;}
// Check for handler metadata added by decorators
const hasHandlerName = !!(exported as any).__handlerName;

View file

@ -3,16 +3,16 @@
* Encapsulates common patterns for Hono-based microservices
*/
import type { AwilixContainer } from 'awilix';
import { Hono } from 'hono';
import { cors } from 'hono/cors';
import type { BaseAppConfig, UnifiedAppConfig } from '@stock-bot/config';
import { toUnifiedConfig } from '@stock-bot/config';
import type { HandlerRegistry } from '@stock-bot/handler-registry';
import { getLogger, setLoggerConfig, shutdownLoggers, type Logger } from '@stock-bot/logger';
import { Shutdown } from '@stock-bot/shutdown';
import type { IServiceContainer } from '@stock-bot/types';
import type { HandlerRegistry } from '@stock-bot/handler-registry';
import type { ServiceDefinitions } from './container/types';
import type { AwilixContainer } from 'awilix';
/**
* Configuration for ServiceApplication
@ -279,8 +279,8 @@ export class ServiceApplication {
if (this.serviceConfig.enableHandlers && handlerInitializer) {
this.logger.debug('Initializing handlers...');
// Pass the service container with the DI container attached
const containerWithDI = Object.assign({}, this.serviceContainer, {
_diContainer: this.container
const containerWithDI = Object.assign({}, this.serviceContainer, {
_diContainer: this.container,
});
await handlerInitializer(containerWithDI);
this.logger.info('Handlers initialized');
@ -339,8 +339,10 @@ export class ServiceApplication {
this.logger.debug('Creating scheduled jobs from registered handlers...');
const handlerRegistry = this.container.resolve<HandlerRegistry>('handlerRegistry');
const allHandlers = handlerRegistry.getAllHandlersWithSchedule();
this.logger.info(`Found ${allHandlers.size} handlers with scheduled jobs: ${Array.from(allHandlers.keys()).join(', ')}`);
this.logger.info(
`Found ${allHandlers.size} handlers with scheduled jobs: ${Array.from(allHandlers.keys()).join(', ')}`
);
let totalScheduledJobs = 0;
for (const [handlerName, config] of allHandlers) {
@ -368,9 +370,9 @@ export class ServiceApplication {
hasHandlerRegistry: !!handlerRegistry,
registeredHandlers: handlerRegistry.getHandlerNames(),
});
const queue = queueManager.getQueue(handlerName, {
handlerRegistry: handlerRegistry
handlerRegistry: handlerRegistry,
});
for (const scheduledJob of config.scheduledJobs) {
@ -395,7 +397,7 @@ export class ServiceApplication {
operation: scheduledJob.operation,
hasOperation: !!handlerRegistry.getOperation(handlerName, scheduledJob.operation),
});
await queue.addScheduledJob(
scheduledJob.operation,
jobData,

View file

@ -7,9 +7,7 @@ import type { JobHandler, ScheduledJob } from '@stock-bot/types';
import type {
HandlerConfiguration,
HandlerMetadata,
OperationMetadata,
RegistryStats,
ScheduleMetadata,
} from './types';
export class HandlerRegistry {

View file

@ -1,3 +1,4 @@
import type { Collection } from 'mongodb';
import { createNamespacedCache } from '@stock-bot/cache';
import { getLogger } from '@stock-bot/logger';
import type {
@ -10,7 +11,6 @@ import type {
ServiceTypes,
} from '@stock-bot/types';
import { fetch } from '@stock-bot/utils';
import type { Collection } from 'mongodb';
// Handler registry is now injected, not imported
import { createJobHandler } from '../utils/create-job-handler';
@ -60,7 +60,7 @@ export abstract class BaseHandler implements IHandler {
const constructor = this.constructor as any;
this.handlerName =
constructor.__handlerName || handlerName || this.constructor.name.toLowerCase();
// Flatten all services onto the handler instance
this.logger = getLogger(this.constructor.name);
this.cache = services.cache;
@ -71,7 +71,7 @@ export abstract class BaseHandler implements IHandler {
this.mongodb = services.mongodb;
this.postgres = services.postgres;
this.questdb = services.questdb;
// Get the specific queue for this handler
if (this.queueManager) {
this.queue = this.queueManager.getQueue(this.handlerName);
@ -336,9 +336,9 @@ export abstract class BaseHandler implements IHandler {
static extractMetadata(): HandlerMetadata | null {
const constructor = this as any;
const handlerName = constructor.__handlerName;
if (!handlerName){
if (!handlerName) {
return null;
}
}
const operations = constructor.__operations || [];
const schedules = constructor.__schedules || [];

View file

@ -1,7 +1,6 @@
// Core exports
export { Queue } from './queue';
export { QueueManager } from './queue-manager';
export { SmartQueueManager } from './smart-queue-manager';
export { ServiceCache, createServiceCache } from './service-cache';
// Service utilities
export {

View file

@ -41,7 +41,7 @@ export class QueueManager {
private shutdownPromise: Promise<void> | null = null;
private config: QueueManagerConfig;
private readonly logger: Logger;
// Service discovery features
private serviceName?: string;
private queueRoutes = new Map<string, QueueRoute>();
@ -59,7 +59,7 @@ export class QueueManager {
},
};
}
this.config = config;
this.serviceName = config.serviceName;
this.handlerRegistry = handlerRegistry;
@ -80,7 +80,7 @@ export class QueueManager {
if (config.serviceName && config.autoDiscoverHandlers !== false && handlerRegistry) {
this.discoverQueueRoutes();
}
this.logger.info('QueueManager initialized', {
redis: `${config.redis.host}:${config.redis.port}`,
service: this.serviceName,
@ -97,11 +97,11 @@ export class QueueManager {
getQueue(queueName: string, options: QueueOptions = {}): Queue {
let fullQueueName = queueName;
let isOwnQueue = true;
// Handle service namespacing if service name is configured
if (this.serviceName) {
const parsed = parseQueueName(queueName);
if (parsed) {
// Already in service:handler format
fullQueueName = queueName;
@ -111,7 +111,7 @@ export class QueueManager {
fullQueueName = getFullQueueName(this.serviceName, queueName);
isOwnQueue = true;
}
// For cross-service queues, create without workers (producer-only)
if (!isOwnQueue) {
options = {
@ -122,10 +122,10 @@ export class QueueManager {
// For own service queues, include handler registry
options = {
...options,
handlerRegistry: this.handlerRegistry
handlerRegistry: this.handlerRegistry,
};
}
queueName = fullQueueName;
}
// Return existing queue if it exists
@ -487,9 +487,11 @@ export class QueueManager {
let workersStarted = 0;
const queues = this.queues;
this.logger.info(`Starting workers for ${queues.size} queues: ${Array.from(queues.keys()).join(', ')} (service: ${this.serviceName})`);
this.logger.info(
`Starting workers for ${queues.size} queues: ${Array.from(queues.keys()).join(', ')} (service: ${this.serviceName})`
);
for (const [queueName, queue] of queues) {
// If we have a service name, check if this queue belongs to us
if (this.serviceName) {
@ -504,7 +506,7 @@ export class QueueManager {
continue;
}
}
const workerCount = this.config.defaultQueueOptions?.workers || 1;
const concurrency = this.config.defaultQueueOptions?.concurrency || 1;
@ -548,7 +550,7 @@ export class QueueManager {
getConfig(): Readonly<QueueManagerConfig> {
return { ...this.config };
}
/**
* Send a job to any queue (local or remote)
* This is the main method for cross-service communication
@ -564,7 +566,7 @@ export class QueueManager {
const queue = this.getQueue(targetQueue);
return queue.add(operation, { handler: targetQueue, operation, payload }, options);
}
// Resolve the target queue
const route = this.resolveQueueRoute(targetQueue);
if (!route) {
@ -582,7 +584,7 @@ export class QueueManager {
// Use a producer queue for cross-service sending
const producerQueue = this.getProducerQueue(route.fullName);
const jobData: JobData = {
handler: route.handler,
operation,
@ -599,7 +601,7 @@ export class QueueManager {
return producerQueue.add(operation, jobData, options);
}
/**
* Resolve a queue name to a route
*/
@ -640,7 +642,7 @@ export class QueueManager {
return null;
}
/**
* Get a producer queue for sending to other services
*/
@ -654,7 +656,7 @@ export class QueueManager {
}
return this.producerQueues.get(queueName)!;
}
/**
* Discover all available queue routes from handler registry
*/

View file

@ -48,7 +48,7 @@ export class Queue {
this.logger = logger || console;
this.handlerRegistry = config.handlerRegistry;
this.serviceName = config.serviceName;
this.logger.debug('Queue constructor called', {
queueName,
serviceName: this.serviceName,
@ -180,7 +180,7 @@ export class Queue {
]);
const isPaused = await this.bullQueue.isPaused();
// Get actual active worker count from BullMQ
const activeWorkerCount = await this.getActiveWorkerCount();
@ -317,7 +317,7 @@ export class Queue {
// Add a name to identify the worker
name: `${this.serviceName || 'unknown'}_worker_${i}`,
});
this.logger.info(`Starting worker ${i + 1}/${workerCount} for queue`, {
queueName: this.queueName,
workerName: worker.name,
@ -380,14 +380,14 @@ export class Queue {
if (!this.handlerRegistry) {
throw new Error('Handler registry not configured for worker processing');
}
this.logger.debug('Looking up handler in registry', {
handler,
operation,
queueName: this.queueName,
registeredHandlers: this.handlerRegistry.getHandlerNames(),
});
const jobHandler = this.handlerRegistry.getOperation(handler, operation);
if (!jobHandler) {
@ -424,7 +424,7 @@ export class Queue {
this.logger.warn('Workers already started for queue', { queueName: this.queueName });
return;
}
this.logger.info('Starting workers manually', {
queueName: this.queueName,
workerCount,
@ -457,9 +457,9 @@ export class Queue {
const workers = await this.bullQueue.getWorkers();
return workers;
} catch (error) {
this.logger.error('Failed to get active workers', {
queueName: this.queueName,
error
this.logger.error('Failed to get active workers', {
queueName: this.queueName,
error,
});
return [];
}
@ -473,9 +473,9 @@ export class Queue {
const workers = await this.bullQueue.getWorkers();
return workers.length;
} catch (error) {
this.logger.error('Failed to get active worker count', {
queueName: this.queueName,
error
this.logger.error('Failed to get active worker count', {
queueName: this.queueName,
error,
});
return 0;
}
@ -484,14 +484,16 @@ export class Queue {
/**
* Get detailed worker information
*/
async getWorkerDetails(): Promise<Array<{
id: string;
name?: string;
addr?: string;
age?: number;
idle?: number;
started?: number;
}>> {
async getWorkerDetails(): Promise<
Array<{
id: string;
name?: string;
addr?: string;
age?: number;
idle?: number;
started?: number;
}>
> {
try {
const workers = await this.bullQueue.getWorkers();
return workers.map(worker => ({
@ -503,13 +505,11 @@ export class Queue {
started: typeof worker.started === 'string' ? parseInt(worker.started) : worker.started,
}));
} catch (error) {
this.logger.error('Failed to get worker details', {
queueName: this.queueName,
error
this.logger.error('Failed to get worker details', {
queueName: this.queueName,
error,
});
return [];
}
}
}

View file

@ -1,18 +0,0 @@
// SmartQueueManager has been merged into QueueManager
// This file is kept for backward compatibility
import { QueueManager } from './queue-manager';
import type { SmartQueueConfig } from './types';
import type { HandlerRegistry } from '@stock-bot/handler-registry';
import type { Logger } from '@stock-bot/logger';
/**
* @deprecated Use QueueManager directly with serviceName config
* SmartQueueManager functionality has been merged into QueueManager
*/
export class SmartQueueManager extends QueueManager {
constructor(config: SmartQueueConfig, handlerRegistry?: HandlerRegistry, logger?: Logger) {
// SmartQueueConfig already has serviceName, just pass it to QueueManager
super(config, handlerRegistry, logger);
}
}