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

@ -1,4 +1,3 @@
import { getRandomUserAgent } from '@stock-bot/utils';
import type { CeoHandler } from '../ceo.handler';
@ -40,7 +39,7 @@ export async function processIndividualSymbol(
}
this.logger.info(
`Successfully processed CEO symbol ${symbol} shorts and found ${shortCount} positions`,
`Successfully processed CEO symbol ${symbol} shorts and found ${shortCount} positions`
);
return { ceoId, shortCount, timestamp };

View file

@ -39,7 +39,11 @@ export async function processIndividualSymbol(
const spielCount = data.spiels.length;
if (spielCount === 0) {
this.logger.warn(`No spiels found for ceoId ${ceoId}`);
await this.mongodb.updateMany('ceoChannels', { ceoId }, { $set: { lastSpielTime: timestamp, finished: true } });
await this.mongodb.updateMany(
'ceoChannels',
{ ceoId },
{ $set: { lastSpielTime: timestamp, finished: true } }
);
return null; // No data to process
}
const latestSpielTime = data.spiels[0]?.timestamp;
@ -77,7 +81,11 @@ export async function processIndividualSymbol(
}));
await this.mongodb.batchUpsert('ceoPosts', posts, ['spielId']);
await this.mongodb.updateMany('ceoChannels', { ceoId }, { $set: { lastSpielTime: latestSpielTime } });
await this.mongodb.updateMany(
'ceoChannels',
{ ceoId },
{ $set: { lastSpielTime: latestSpielTime } }
);
this.logger.info(`Fetched ${spielCount} spiels for ceoId ${ceoId}`);
await this.scheduleOperation(

View file

@ -1,9 +1,4 @@
import {
BaseHandler,
Handler,
Operation,
ScheduledOperation,
} from '@stock-bot/handlers';
import { BaseHandler, Handler, Operation, ScheduledOperation } from '@stock-bot/handlers';
import type { IServiceContainer } from '@stock-bot/types';
import { clearPostgreSQLData } from './operations/clear-postgresql-data.operations';
import { getSyncStatus } from './operations/enhanced-sync-status.operations';

View file

@ -1,5 +1,5 @@
import type { IServiceContainer } from '@stock-bot/types';
import { getLogger } from '@stock-bot/logger';
import type { IServiceContainer } from '@stock-bot/types';
import type { JobPayload } from '../../../types/job-payloads';
const logger = getLogger('sync-qm-exchanges');

View file

@ -2,8 +2,8 @@
* Exchange management routes - Refactored
*/
import { Hono } from 'hono';
import type { IServiceContainer } from '@stock-bot/types';
import { getLogger } from '@stock-bot/logger';
import type { IServiceContainer } from '@stock-bot/types';
import { createExchangeService } from '../services/exchange.service';
import { createSuccessResponse, handleError } from '../utils/error-handler';
import {

View file

@ -1,5 +1,5 @@
import type { IServiceContainer } from '@stock-bot/types';
import { getLogger } from '@stock-bot/logger';
import type { IServiceContainer } from '@stock-bot/types';
import {
CreateExchangeRequest,
CreateProviderMappingRequest,

View file

@ -316,7 +316,7 @@ export class RedisCache implements CacheProvider {
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
@ -280,7 +280,7 @@ export class ServiceApplication {
this.logger.debug('Initializing handlers...');
// Pass the service container with the DI container attached
const containerWithDI = Object.assign({}, this.serviceContainer, {
_diContainer: this.container
_diContainer: this.container,
});
await handlerInitializer(containerWithDI);
this.logger.info('Handlers initialized');
@ -340,7 +340,9 @@ export class ServiceApplication {
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) {
@ -370,7 +372,7 @@ export class ServiceApplication {
});
const queue = queueManager.getQueue(handlerName, {
handlerRegistry: handlerRegistry
handlerRegistry: handlerRegistry,
});
for (const scheduledJob of config.scheduledJobs) {

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';
@ -336,7 +336,7 @@ 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;
}

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

@ -122,7 +122,7 @@ export class QueueManager {
// For own service queues, include handler registry
options = {
...options,
handlerRegistry: this.handlerRegistry
handlerRegistry: this.handlerRegistry,
};
}
@ -488,7 +488,9 @@ 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

View file

@ -459,7 +459,7 @@ export class Queue {
} catch (error) {
this.logger.error('Failed to get active workers', {
queueName: this.queueName,
error
error,
});
return [];
}
@ -475,7 +475,7 @@ export class Queue {
} catch (error) {
this.logger.error('Failed to get active worker count', {
queueName: this.queueName,
error
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 => ({
@ -505,11 +507,9 @@ export class Queue {
} catch (error) {
this.logger.error('Failed to get worker details', {
queueName: this.queueName,
error
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);
}
}