simplified a lot of stuff

This commit is contained in:
Boki 2025-06-26 15:34:48 -04:00
parent b845a8eade
commit 885b484a37
20 changed files with 360 additions and 1335 deletions

View file

@ -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');
}
/**