switched all console logs to logger
This commit is contained in:
parent
3877902ff4
commit
a3f2f199b4
14 changed files with 125 additions and 122 deletions
Binary file not shown.
|
|
@ -1,85 +1,87 @@
|
||||||
import { ConfigManager, createAppConfig } from '@stock-bot/config';
|
import { ConfigManager, createAppConfig } from '@stock-bot/config';
|
||||||
import { stockAppSchema, type StockAppConfig } from './schemas';
|
import { stockAppSchema, type StockAppConfig } from './schemas';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
|
import { getLogger } from '@stock-bot/logger';
|
||||||
let configInstance: ConfigManager<StockAppConfig> | null = null;
|
|
||||||
|
let configInstance: ConfigManager<StockAppConfig> | null = null;
|
||||||
/**
|
|
||||||
* Initialize the stock application configuration
|
/**
|
||||||
* @param serviceName - Optional service name to override port configuration
|
* Initialize the stock application configuration
|
||||||
*/
|
* @param serviceName - Optional service name to override port configuration
|
||||||
export function initializeStockConfig(serviceName?: 'dataIngestion' | 'dataPipeline' | 'webApi'): StockAppConfig {
|
*/
|
||||||
try {
|
export function initializeStockConfig(serviceName?: 'dataIngestion' | 'dataPipeline' | 'webApi'): StockAppConfig {
|
||||||
if (!configInstance) {
|
try {
|
||||||
configInstance = createAppConfig(stockAppSchema, {
|
if (!configInstance) {
|
||||||
configPath: path.join(__dirname, '../config'),
|
configInstance = createAppConfig(stockAppSchema, {
|
||||||
});
|
configPath: path.join(__dirname, '../config'),
|
||||||
}
|
});
|
||||||
|
}
|
||||||
const config = configInstance.initialize(stockAppSchema);
|
|
||||||
|
const config = configInstance.initialize(stockAppSchema);
|
||||||
// If a service name is provided, override the service port
|
|
||||||
if (serviceName && config.services?.[serviceName]) {
|
// If a service name is provided, override the service port
|
||||||
const kebabName = serviceName.replace(/([A-Z])/g, '-$1').toLowerCase().replace(/^-/, '');
|
if (serviceName && config.services?.[serviceName]) {
|
||||||
return {
|
const kebabName = serviceName.replace(/([A-Z])/g, '-$1').toLowerCase().replace(/^-/, '');
|
||||||
...config,
|
return {
|
||||||
service: {
|
...config,
|
||||||
...config.service,
|
service: {
|
||||||
port: config.services[serviceName].port,
|
...config.service,
|
||||||
name: serviceName, // Keep original for backward compatibility
|
port: config.services[serviceName].port,
|
||||||
serviceName: kebabName // Standard kebab-case name
|
name: serviceName, // Keep original for backward compatibility
|
||||||
}
|
serviceName: kebabName // Standard kebab-case name
|
||||||
};
|
}
|
||||||
}
|
};
|
||||||
|
}
|
||||||
return config;
|
|
||||||
} catch (error: any) {
|
return config;
|
||||||
console.error('Failed to initialize stock configuration:', error.message);
|
} catch (error: any) {
|
||||||
if (error.errors) {
|
const logger = getLogger('stock-config');
|
||||||
console.error('Validation errors:', JSON.stringify(error.errors, null, 2));
|
logger.error('Failed to initialize stock configuration:', error.message);
|
||||||
}
|
if (error.errors) {
|
||||||
throw error;
|
logger.error('Validation errors:', error.errors);
|
||||||
}
|
}
|
||||||
}
|
throw error;
|
||||||
|
}
|
||||||
/**
|
}
|
||||||
* Get the current stock configuration
|
|
||||||
*/
|
/**
|
||||||
export function getStockConfig(): StockAppConfig {
|
* Get the current stock configuration
|
||||||
if (!configInstance) {
|
*/
|
||||||
// Auto-initialize if not already done
|
export function getStockConfig(): StockAppConfig {
|
||||||
return initializeStockConfig();
|
if (!configInstance) {
|
||||||
}
|
// Auto-initialize if not already done
|
||||||
return configInstance.get();
|
return initializeStockConfig();
|
||||||
}
|
}
|
||||||
|
return configInstance.get();
|
||||||
/**
|
}
|
||||||
* Get configuration for a specific service
|
|
||||||
*/
|
/**
|
||||||
export function getServiceConfig(service: 'dataIngestion' | 'dataPipeline' | 'webApi') {
|
* Get configuration for a specific service
|
||||||
const config = getStockConfig();
|
*/
|
||||||
return config.services?.[service];
|
export function getServiceConfig(service: 'dataIngestion' | 'dataPipeline' | 'webApi') {
|
||||||
}
|
const config = getStockConfig();
|
||||||
|
return config.services?.[service];
|
||||||
/**
|
}
|
||||||
* Get configuration for a specific provider
|
|
||||||
*/
|
/**
|
||||||
export function getProviderConfig(provider: 'eod' | 'ib' | 'qm' | 'yahoo') {
|
* Get configuration for a specific provider
|
||||||
const config = getStockConfig();
|
*/
|
||||||
return config.providers[provider];
|
export function getProviderConfig(provider: 'eod' | 'ib' | 'qm' | 'yahoo') {
|
||||||
}
|
const config = getStockConfig();
|
||||||
|
return config.providers[provider];
|
||||||
/**
|
}
|
||||||
* Check if a feature is enabled
|
|
||||||
*/
|
/**
|
||||||
export function isFeatureEnabled(feature: keyof StockAppConfig['features']): boolean {
|
* Check if a feature is enabled
|
||||||
const config = getStockConfig();
|
*/
|
||||||
return config.features[feature];
|
export function isFeatureEnabled(feature: keyof StockAppConfig['features']): boolean {
|
||||||
}
|
const config = getStockConfig();
|
||||||
|
return config.features[feature];
|
||||||
/**
|
}
|
||||||
* Reset configuration (useful for testing)
|
|
||||||
*/
|
/**
|
||||||
export function resetStockConfig(): void {
|
* Reset configuration (useful for testing)
|
||||||
configInstance = null;
|
*/
|
||||||
|
export function resetStockConfig(): void {
|
||||||
|
configInstance = null;
|
||||||
}
|
}
|
||||||
|
|
@ -19,7 +19,7 @@ export async function checkSessions(handler: BaseHandler): Promise<{
|
||||||
// Check which session IDs need more sessions and queue creation jobs
|
// Check which session IDs need more sessions and queue creation jobs
|
||||||
let queuedCount = 0;
|
let queuedCount = 0;
|
||||||
for (const [sessionType, sessionId] of Object.entries(QM_SESSION_IDS)) {
|
for (const [sessionType, sessionId] of Object.entries(QM_SESSION_IDS)) {
|
||||||
console.log(`Checking session ID: ${sessionId}`);
|
handler.logger.debug(`Checking session ID: ${sessionId}`);
|
||||||
if (sessionManager.needsMoreSessions(sessionId)) {
|
if (sessionManager.needsMoreSessions(sessionId)) {
|
||||||
const currentCount = sessionManager.getSessions(sessionId).length;
|
const currentCount = sessionManager.getSessions(sessionId).length;
|
||||||
const neededSessions = SESSION_CONFIG.MAX_SESSIONS - currentCount;
|
const neededSessions = SESSION_CONFIG.MAX_SESSIONS - currentCount;
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ import { createRoutes } from './routes/create-routes';
|
||||||
|
|
||||||
// Initialize configuration with service-specific overrides
|
// Initialize configuration with service-specific overrides
|
||||||
const config = initializeStockConfig('dataIngestion');
|
const config = initializeStockConfig('dataIngestion');
|
||||||
console.log('Data Ingestion Service Configuration:', JSON.stringify(config, null, 2));
|
|
||||||
|
|
||||||
// Create service application
|
// Create service application
|
||||||
const app = new ServiceApplication(
|
const app = new ServiceApplication(
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ import { setupServiceContainer } from './container-setup';
|
||||||
|
|
||||||
// Initialize configuration with service-specific overrides
|
// Initialize configuration with service-specific overrides
|
||||||
const config = initializeStockConfig('dataPipeline');
|
const config = initializeStockConfig('dataPipeline');
|
||||||
console.log('Data Pipeline Service Configuration:', JSON.stringify(config, null, 2));
|
|
||||||
|
|
||||||
// Create service application
|
// Create service application
|
||||||
const app = new ServiceApplication(
|
const app = new ServiceApplication(
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ if (config.queue) {
|
||||||
config.queue.delayWorkerStart = true;
|
config.queue.delayWorkerStart = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('Web API Service Configuration:', JSON.stringify(config, null, 2));
|
|
||||||
|
|
||||||
// Create service application
|
// Create service application
|
||||||
const app = new ServiceApplication(
|
const app = new ServiceApplication(
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ import { z } from 'zod';
|
||||||
import { EnvLoader } from './loaders/env.loader';
|
import { EnvLoader } from './loaders/env.loader';
|
||||||
import { FileLoader } from './loaders/file.loader';
|
import { FileLoader } from './loaders/file.loader';
|
||||||
import { ConfigError, ConfigValidationError } from './errors';
|
import { ConfigError, ConfigValidationError } from './errors';
|
||||||
|
import { getLogger } from '@stock-bot/logger';
|
||||||
import type {
|
import type {
|
||||||
ConfigLoader,
|
ConfigLoader,
|
||||||
ConfigManagerOptions,
|
ConfigManagerOptions,
|
||||||
|
|
@ -12,6 +13,7 @@ import type {
|
||||||
} from './types';
|
} from './types';
|
||||||
|
|
||||||
export class ConfigManager<T = Record<string, unknown>> {
|
export class ConfigManager<T = Record<string, unknown>> {
|
||||||
|
private readonly logger = getLogger('config-manager');
|
||||||
private config: T | null = null;
|
private config: T | null = null;
|
||||||
private loaders: ConfigLoader[];
|
private loaders: ConfigLoader[];
|
||||||
private environment: Environment;
|
private environment: Environment;
|
||||||
|
|
@ -81,8 +83,7 @@ export class ConfigManager<T = Record<string, unknown>> {
|
||||||
received: (err as any).received,
|
received: (err as any).received,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
console.error('Configuration validation failed:');
|
this.logger.error('Configuration validation failed:', errorDetails);
|
||||||
console.error(JSON.stringify(errorDetails, null, 2));
|
|
||||||
|
|
||||||
throw new ConfigValidationError('Configuration validation failed', error.errors);
|
throw new ConfigValidationError('Configuration validation failed', error.errors);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ export function registerCacheServices(
|
||||||
): void {
|
): void {
|
||||||
if (config.redis.enabled) {
|
if (config.redis.enabled) {
|
||||||
container.register({
|
container.register({
|
||||||
cache: asFunction(() => {
|
cache: asFunction(({ logger }) => {
|
||||||
const { createServiceCache } = require('@stock-bot/queue');
|
const { createServiceCache } = require('@stock-bot/queue');
|
||||||
// Get standardized service name from config
|
// Get standardized service name from config
|
||||||
const serviceName = config.service?.serviceName || config.service?.name || 'unknown';
|
const serviceName = config.service?.serviceName || config.service?.name || 'unknown';
|
||||||
|
|
@ -20,11 +20,11 @@ export function registerCacheServices(
|
||||||
port: config.redis.port,
|
port: config.redis.port,
|
||||||
password: config.redis.password,
|
password: config.redis.password,
|
||||||
db: config.redis.db, // This will be overridden by ServiceCache
|
db: config.redis.db, // This will be overridden by ServiceCache
|
||||||
});
|
}, { logger });
|
||||||
}).singleton(),
|
}).singleton(),
|
||||||
|
|
||||||
// Also provide global cache for shared data
|
// Also provide global cache for shared data
|
||||||
globalCache: asFunction(() => {
|
globalCache: asFunction(({ logger }) => {
|
||||||
const { createServiceCache } = require('@stock-bot/queue');
|
const { createServiceCache } = require('@stock-bot/queue');
|
||||||
const serviceName = config.service?.serviceName || config.service?.name || 'unknown';
|
const serviceName = config.service?.serviceName || config.service?.name || 'unknown';
|
||||||
|
|
||||||
|
|
@ -32,7 +32,7 @@ export function registerCacheServices(
|
||||||
host: config.redis.host,
|
host: config.redis.host,
|
||||||
port: config.redis.port,
|
port: config.redis.port,
|
||||||
password: config.redis.password,
|
password: config.redis.password,
|
||||||
}, { global: true });
|
}, { global: true, logger });
|
||||||
}).singleton(),
|
}).singleton(),
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -313,7 +313,7 @@ export class ServiceApplication {
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('DETAILED ERROR:', error);
|
this.logger.error('DETAILED ERROR:', error);
|
||||||
this.logger.error('Failed to start service', {
|
this.logger.error('Failed to start service', {
|
||||||
error: error instanceof Error ? error.message : String(error),
|
error: error instanceof Error ? error.message : String(error),
|
||||||
stack: error instanceof Error ? error.stack : undefined,
|
stack: error instanceof Error ? error.stack : undefined,
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
import type { AwilixContainer } from 'awilix';
|
import type { AwilixContainer } from 'awilix';
|
||||||
import type { ServiceDefinitions } from '../container/types';
|
import type { ServiceDefinitions } from '../container/types';
|
||||||
|
import { getLogger } from '@stock-bot/logger';
|
||||||
|
|
||||||
interface ServiceWithLifecycle {
|
interface ServiceWithLifecycle {
|
||||||
connect?: () => Promise<void>;
|
connect?: () => Promise<void>;
|
||||||
|
|
@ -10,6 +11,7 @@ interface ServiceWithLifecycle {
|
||||||
}
|
}
|
||||||
|
|
||||||
export class ServiceLifecycleManager {
|
export class ServiceLifecycleManager {
|
||||||
|
private readonly logger = getLogger('service-lifecycle');
|
||||||
private readonly services = [
|
private readonly services = [
|
||||||
{ name: 'cache', key: 'cache' as const },
|
{ name: 'cache', key: 'cache' as const },
|
||||||
{ name: 'mongoClient', key: 'mongoClient' as const },
|
{ name: 'mongoClient', key: 'mongoClient' as const },
|
||||||
|
|
@ -40,7 +42,7 @@ export class ServiceLifecycleManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
await Promise.all(initPromises);
|
await Promise.all(initPromises);
|
||||||
console.log('✅ All services initialized successfully');
|
this.logger.info('All services initialized successfully');
|
||||||
}
|
}
|
||||||
|
|
||||||
async shutdownServices(container: AwilixContainer<ServiceDefinitions>): Promise<void> {
|
async shutdownServices(container: AwilixContainer<ServiceDefinitions>): Promise<void> {
|
||||||
|
|
@ -56,20 +58,20 @@ export class ServiceLifecycleManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
await Promise.allSettled(shutdownPromises);
|
await Promise.allSettled(shutdownPromises);
|
||||||
console.log('✅ All services shut down');
|
this.logger.info('All services shut down');
|
||||||
}
|
}
|
||||||
|
|
||||||
private async initializeService(name: string, service: ServiceWithLifecycle): Promise<void> {
|
private async initializeService(name: string, service: ServiceWithLifecycle): Promise<void> {
|
||||||
try {
|
try {
|
||||||
if (typeof service.connect === 'function') {
|
if (typeof service.connect === 'function') {
|
||||||
await service.connect();
|
await service.connect();
|
||||||
console.log(`✅ ${name} connected`);
|
this.logger.info(`${name} connected`);
|
||||||
} else if (typeof service.initialize === 'function') {
|
} else if (typeof service.initialize === 'function') {
|
||||||
await service.initialize();
|
await service.initialize();
|
||||||
console.log(`✅ ${name} initialized`);
|
this.logger.info(`${name} initialized`);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(`❌ Failed to initialize ${name}:`, error);
|
this.logger.error(`Failed to initialize ${name}:`, error);
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -83,9 +85,9 @@ export class ServiceLifecycleManager {
|
||||||
} else if (typeof service.shutdown === 'function') {
|
} else if (typeof service.shutdown === 'function') {
|
||||||
await service.shutdown();
|
await service.shutdown();
|
||||||
}
|
}
|
||||||
console.log(`✅ ${name} shut down`);
|
this.logger.info(`${name} shut down`);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(`❌ Error shutting down ${name}:`, error);
|
this.logger.error(`Error shutting down ${name}:`, error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -94,4 +96,4 @@ export class ServiceLifecycleManager {
|
||||||
setTimeout(() => reject(new Error(message)), timeout);
|
setTimeout(() => reject(new Error(message)), timeout);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,8 +9,10 @@ import type {
|
||||||
JobHandler,
|
JobHandler,
|
||||||
ScheduledJob,
|
ScheduledJob,
|
||||||
} from './handlers';
|
} from './handlers';
|
||||||
|
import { getLogger } from '@stock-bot/logger';
|
||||||
|
|
||||||
class HandlerRegistry {
|
class HandlerRegistry {
|
||||||
|
private readonly logger = getLogger('handler-registry');
|
||||||
private handlers = new Map<string, HandlerConfig>();
|
private handlers = new Map<string, HandlerConfig>();
|
||||||
private handlerSchedules = new Map<string, ScheduledJob[]>();
|
private handlerSchedules = new Map<string, ScheduledJob[]>();
|
||||||
|
|
||||||
|
|
@ -18,7 +20,7 @@ class HandlerRegistry {
|
||||||
* Register a handler with its operations (simple config)
|
* Register a handler with its operations (simple config)
|
||||||
*/
|
*/
|
||||||
register(handlerName: string, config: HandlerConfig): void {
|
register(handlerName: string, config: HandlerConfig): void {
|
||||||
console.log(`Registering handler: ${handlerName}`, {
|
this.logger.info(`Registering handler: ${handlerName}`, {
|
||||||
operations: Object.keys(config),
|
operations: Object.keys(config),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -29,7 +31,7 @@ class HandlerRegistry {
|
||||||
* Register a handler with scheduled jobs (enhanced config)
|
* Register a handler with scheduled jobs (enhanced config)
|
||||||
*/
|
*/
|
||||||
registerWithSchedule(config: HandlerConfigWithSchedule): void {
|
registerWithSchedule(config: HandlerConfigWithSchedule): void {
|
||||||
console.log(`Registering handler with schedule: ${config.name}`, {
|
this.logger.info(`Registering handler with schedule: ${config.name}`, {
|
||||||
operations: Object.keys(config.operations),
|
operations: Object.keys(config.operations),
|
||||||
scheduledJobs: config.scheduledJobs?.length || 0,
|
scheduledJobs: config.scheduledJobs?.length || 0,
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -38,11 +38,6 @@ export class QuestDBClient {
|
||||||
};
|
};
|
||||||
|
|
||||||
// Debug: log the received config
|
// Debug: log the received config
|
||||||
console.log('DEBUG: QuestDB client constructor called with config:', {
|
|
||||||
...config,
|
|
||||||
user: config.user || '[NOT PROVIDED]',
|
|
||||||
password: config.password ? '[PROVIDED]' : '[NOT PROVIDED]',
|
|
||||||
});
|
|
||||||
this.logger.debug('QuestDB client created with config:', {
|
this.logger.debug('QuestDB client created with config:', {
|
||||||
...config,
|
...config,
|
||||||
user: config.user || '[NOT PROVIDED]',
|
user: config.user || '[NOT PROVIDED]',
|
||||||
|
|
@ -435,27 +430,24 @@ export class QuestDBClient {
|
||||||
|
|
||||||
// Only add user/password if they are provided
|
// Only add user/password if they are provided
|
||||||
if (this.config.user) {
|
if (this.config.user) {
|
||||||
console.log('DEBUG: Adding user to QuestDB pool config:', this.config.user);
|
|
||||||
this.logger.debug('Adding user to QuestDB pool config:', this.config.user);
|
this.logger.debug('Adding user to QuestDB pool config:', this.config.user);
|
||||||
config.user = this.config.user;
|
config.user = this.config.user;
|
||||||
} else {
|
} else {
|
||||||
console.log('DEBUG: No user provided for QuestDB connection');
|
|
||||||
this.logger.debug('No user provided for QuestDB connection');
|
this.logger.debug('No user provided for QuestDB connection');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.config.password) {
|
if (this.config.password) {
|
||||||
console.log('DEBUG: Adding password to QuestDB pool config');
|
|
||||||
this.logger.debug('Adding password to QuestDB pool config');
|
this.logger.debug('Adding password to QuestDB pool config');
|
||||||
config.password = this.config.password;
|
config.password = this.config.password;
|
||||||
} else {
|
} else {
|
||||||
console.log('DEBUG: No password provided for QuestDB connection');
|
|
||||||
this.logger.debug('No password provided for QuestDB connection');
|
this.logger.debug('No password provided for QuestDB connection');
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('DEBUG: Final QuestDB pool config:', {
|
|
||||||
...config,
|
|
||||||
password: config.password ? '[REDACTED]' : undefined,
|
|
||||||
});
|
|
||||||
this.logger.debug('Final QuestDB pool config:', {
|
this.logger.debug('Final QuestDB pool config:', {
|
||||||
...config,
|
...config,
|
||||||
password: config.password ? '[REDACTED]' : undefined,
|
password: config.password ? '[REDACTED]' : undefined,
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,8 @@ export class ServiceCache implements CacheProvider {
|
||||||
constructor(
|
constructor(
|
||||||
serviceName: string,
|
serviceName: string,
|
||||||
redisConfig: RedisConfig,
|
redisConfig: RedisConfig,
|
||||||
isGlobalCache: boolean = false
|
isGlobalCache: boolean = false,
|
||||||
|
logger?: any
|
||||||
) {
|
) {
|
||||||
// Get service configuration
|
// Get service configuration
|
||||||
const serviceConfig = getServiceConfig(serviceName);
|
const serviceConfig = getServiceConfig(serviceName);
|
||||||
|
|
@ -42,6 +43,7 @@ export class ServiceCache implements CacheProvider {
|
||||||
db,
|
db,
|
||||||
},
|
},
|
||||||
keyPrefix: prefix + ':',
|
keyPrefix: prefix + ':',
|
||||||
|
logger,
|
||||||
};
|
};
|
||||||
|
|
||||||
this.cache = createCache(cacheConfig);
|
this.cache = createCache(cacheConfig);
|
||||||
|
|
@ -161,7 +163,7 @@ export class ServiceCache implements CacheProvider {
|
||||||
export function createServiceCache(
|
export function createServiceCache(
|
||||||
serviceName: string,
|
serviceName: string,
|
||||||
redisConfig: RedisConfig,
|
redisConfig: RedisConfig,
|
||||||
options: { global?: boolean } = {}
|
options: { global?: boolean; logger?: any } = {}
|
||||||
): ServiceCache {
|
): ServiceCache {
|
||||||
return new ServiceCache(serviceName, redisConfig, options.global);
|
return new ServiceCache(serviceName, redisConfig, options.global, options.logger);
|
||||||
}
|
}
|
||||||
|
|
@ -14,6 +14,7 @@ import type {
|
||||||
ShutdownOptions,
|
ShutdownOptions,
|
||||||
ShutdownResult,
|
ShutdownResult,
|
||||||
} from './types';
|
} from './types';
|
||||||
|
import { getLogger } from '@stock-bot/logger';
|
||||||
|
|
||||||
// Global flag that works across all processes/workers
|
// Global flag that works across all processes/workers
|
||||||
declare global {
|
declare global {
|
||||||
|
|
@ -22,6 +23,7 @@ declare global {
|
||||||
|
|
||||||
export class Shutdown {
|
export class Shutdown {
|
||||||
private static instance: Shutdown | null = null;
|
private static instance: Shutdown | null = null;
|
||||||
|
private readonly logger = getLogger('shutdown');
|
||||||
private isShuttingDown = false;
|
private isShuttingDown = false;
|
||||||
private signalReceived = false; // Track if shutdown signal was received
|
private signalReceived = false; // Track if shutdown signal was received
|
||||||
private shutdownTimeout = 30000; // 30 seconds default
|
private shutdownTimeout = 30000; // 30 seconds default
|
||||||
|
|
@ -200,7 +202,7 @@ export class Shutdown {
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
failed++;
|
failed++;
|
||||||
if (name) {
|
if (name) {
|
||||||
console.error(`✗ Shutdown failed: ${name} (priority: ${priority})`, error);
|
this.logger.error(`Shutdown failed: ${name} (priority: ${priority})`, error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue