simplified a lot of stuff
This commit is contained in:
parent
b845a8eade
commit
885b484a37
20 changed files with 360 additions and 1335 deletions
|
|
@ -1,39 +1,3 @@
|
|||
// Export all dependency injection components
|
||||
export * from './operation-context';
|
||||
export * from './pool-size-calculator';
|
||||
export * from './types';
|
||||
|
||||
// Re-export IServiceContainer from types for convenience
|
||||
export type { IServiceContainer } from '@stock-bot/types';
|
||||
|
||||
// Type exports from awilix-container
|
||||
export {
|
||||
type AppConfig,
|
||||
type ServiceCradle,
|
||||
type ServiceContainer,
|
||||
type ServiceContainerOptions,
|
||||
} from './awilix-container';
|
||||
|
||||
// New modular structure exports
|
||||
export * from './container/types';
|
||||
export { ServiceContainerBuilder } from './container/builder';
|
||||
|
||||
// Configuration exports
|
||||
export * from './config/schemas';
|
||||
|
||||
// Factory exports
|
||||
export * from './factories';
|
||||
|
||||
// Utility exports
|
||||
export { ServiceLifecycleManager } from './utils/lifecycle';
|
||||
|
||||
// Service application framework
|
||||
export {
|
||||
ServiceApplication,
|
||||
type ServiceApplicationConfig,
|
||||
type ServiceLifecycleHooks,
|
||||
} from './service-application';
|
||||
|
||||
// Handler scanner
|
||||
export { HandlerScanner } from './scanner';
|
||||
export type { HandlerScannerOptions } from './scanner';
|
||||
// Export only what's actually used
|
||||
export { ServiceApplication } from './service-application';
|
||||
export { ServiceContainerBuilder } from './container/builder';
|
||||
|
|
@ -2,7 +2,7 @@ import { asFunction, asValue, type AwilixContainer } from 'awilix';
|
|||
import { MongoDBClient } from '@stock-bot/mongodb';
|
||||
import { PostgreSQLClient } from '@stock-bot/postgres';
|
||||
import { QuestDBClient } from '@stock-bot/questdb';
|
||||
import type { AppConfig } from '../config/schemas';
|
||||
import type { AppConfig } from '../config/schemas/index';
|
||||
import type { ServiceDefinitions } from '../container/types';
|
||||
|
||||
export function registerDatabaseServices(
|
||||
|
|
|
|||
|
|
@ -10,7 +10,6 @@ import type {
|
|||
HandlerMetadata,
|
||||
HandlerRegistry,
|
||||
} from '@stock-bot/handler-registry';
|
||||
import { createJobHandler } from '@stock-bot/handlers';
|
||||
import { getLogger } from '@stock-bot/logger';
|
||||
import type { ExecutionContext, IHandler } from '@stock-bot/types';
|
||||
|
||||
|
|
@ -129,14 +128,14 @@ export class HandlerScanner {
|
|||
// Build configuration with operation handlers
|
||||
const operationHandlers: Record<string, any> = {};
|
||||
for (const op of operations) {
|
||||
operationHandlers[op.name] = createJobHandler(async payload => {
|
||||
operationHandlers[op.name] = async (payload: any) => {
|
||||
const handler = this.container.resolve<IHandler>(handlerName);
|
||||
const context: ExecutionContext = {
|
||||
type: 'queue',
|
||||
metadata: { source: 'queue', timestamp: Date.now() },
|
||||
};
|
||||
return await handler.execute(op.name, payload, context);
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
const configuration: HandlerConfiguration = {
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ 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 { Shutdown, SHUTDOWN_DEFAULTS } from '@stock-bot/shutdown';
|
||||
import type { IServiceContainer } from '@stock-bot/types';
|
||||
import type { ServiceDefinitions } from './container/types';
|
||||
|
||||
|
|
@ -166,7 +166,7 @@ export class ServiceApplication {
|
|||
private registerShutdownHandlers(): void {
|
||||
// Priority 1: Queue system (highest priority)
|
||||
if (this.serviceConfig.enableScheduledJobs) {
|
||||
this.shutdown.onShutdownHigh(async () => {
|
||||
this.shutdown.onShutdown(async () => {
|
||||
this.logger.info('Shutting down queue system...');
|
||||
try {
|
||||
const queueManager = this.container?.resolve('queueManager');
|
||||
|
|
@ -177,11 +177,11 @@ export class ServiceApplication {
|
|||
} catch (error) {
|
||||
this.logger.error('Error shutting down queue system', { error });
|
||||
}
|
||||
}, 'Queue System');
|
||||
}, SHUTDOWN_DEFAULTS.HIGH_PRIORITY, 'Queue System');
|
||||
}
|
||||
|
||||
// Priority 1: HTTP Server (high priority)
|
||||
this.shutdown.onShutdownHigh(async () => {
|
||||
this.shutdown.onShutdown(async () => {
|
||||
if (this.server) {
|
||||
this.logger.info('Stopping HTTP server...');
|
||||
try {
|
||||
|
|
@ -191,21 +191,21 @@ export class ServiceApplication {
|
|||
this.logger.error('Error stopping HTTP server', { error });
|
||||
}
|
||||
}
|
||||
}, 'HTTP Server');
|
||||
}, SHUTDOWN_DEFAULTS.HIGH_PRIORITY, 'HTTP Server');
|
||||
|
||||
// Custom shutdown hook
|
||||
if (this.hooks.onBeforeShutdown) {
|
||||
this.shutdown.onShutdownHigh(async () => {
|
||||
this.shutdown.onShutdown(async () => {
|
||||
try {
|
||||
await this.hooks.onBeforeShutdown!();
|
||||
} catch (error) {
|
||||
this.logger.error('Error in custom shutdown hook', { error });
|
||||
}
|
||||
}, 'Custom Shutdown');
|
||||
}, SHUTDOWN_DEFAULTS.HIGH_PRIORITY, 'Custom Shutdown');
|
||||
}
|
||||
|
||||
// Priority 2: Services and connections (medium priority)
|
||||
this.shutdown.onShutdownMedium(async () => {
|
||||
this.shutdown.onShutdown(async () => {
|
||||
this.logger.info('Disposing services and connections...');
|
||||
try {
|
||||
if (this.container) {
|
||||
|
|
@ -230,10 +230,10 @@ export class ServiceApplication {
|
|||
} catch (error) {
|
||||
this.logger.error('Error disposing services', { error });
|
||||
}
|
||||
}, 'Services');
|
||||
}, SHUTDOWN_DEFAULTS.MEDIUM_PRIORITY, 'Services');
|
||||
|
||||
// Priority 3: Logger shutdown (lowest priority - runs last)
|
||||
this.shutdown.onShutdownLow(async () => {
|
||||
this.shutdown.onShutdown(async () => {
|
||||
try {
|
||||
this.logger.info('Shutting down loggers...');
|
||||
await shutdownLoggers();
|
||||
|
|
@ -241,7 +241,7 @@ export class ServiceApplication {
|
|||
} catch {
|
||||
// Silently ignore logger shutdown errors
|
||||
}
|
||||
}, 'Loggers');
|
||||
}, SHUTDOWN_DEFAULTS.LOW_PRIORITY, 'Loggers');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue