fixed format issues

This commit is contained in:
Boki 2025-06-26 16:12:27 -04:00
parent a700818a06
commit 08f713d98b
55 changed files with 5680 additions and 5533 deletions

View file

@ -1,35 +1,35 @@
/**
* Core constants used across the stock-bot application
*/
// Cache constants
export const CACHE_DEFAULTS = {
TTL: 3600, // 1 hour in seconds
KEY_PREFIX: 'cache:',
SCAN_COUNT: 100,
} as const;
// Redis connection constants
export const REDIS_DEFAULTS = {
DB: 0,
MAX_RETRIES: 3,
RETRY_DELAY: 100,
CONNECT_TIMEOUT: 10000,
COMMAND_TIMEOUT: 5000,
KEEP_ALIVE: 0,
} as const;
// Shutdown constants
export const SHUTDOWN_DEFAULTS = {
TIMEOUT: 30000, // 30 seconds
HIGH_PRIORITY: 10,
MEDIUM_PRIORITY: 50,
LOW_PRIORITY: 90,
} as const;
// Pool size constants
export const POOL_SIZE_DEFAULTS = {
MIN_POOL_SIZE: 2,
MAX_POOL_SIZE: 10,
CPU_MULTIPLIER: 2,
} as const;
/**
* Core constants used across the stock-bot application
*/
// Cache constants
export const CACHE_DEFAULTS = {
TTL: 3600, // 1 hour in seconds
KEY_PREFIX: 'cache:',
SCAN_COUNT: 100,
} as const;
// Redis connection constants
export const REDIS_DEFAULTS = {
DB: 0,
MAX_RETRIES: 3,
RETRY_DELAY: 100,
CONNECT_TIMEOUT: 10000,
COMMAND_TIMEOUT: 5000,
KEEP_ALIVE: 0,
} as const;
// Shutdown constants
export const SHUTDOWN_DEFAULTS = {
TIMEOUT: 30000, // 30 seconds
HIGH_PRIORITY: 10,
MEDIUM_PRIORITY: 50,
LOW_PRIORITY: 90,
} as const;
// Pool size constants
export const POOL_SIZE_DEFAULTS = {
MIN_POOL_SIZE: 2,
MAX_POOL_SIZE: 10,
CPU_MULTIPLIER: 2,
} as const;

View file

@ -12,4 +12,4 @@ export function onShutdown(
): void {
const shutdown = Shutdown.getInstance();
shutdown.onShutdown(callback, priority, name);
}
}

View file

@ -33,8 +33,14 @@ export class Shutdown {
/**
* Register a cleanup callback
*/
onShutdown(callback: ShutdownCallback, priority: number = SHUTDOWN_DEFAULTS.MEDIUM_PRIORITY, name?: string): void {
if (this.isShuttingDown) { return };
onShutdown(
callback: ShutdownCallback,
priority: number = SHUTDOWN_DEFAULTS.MEDIUM_PRIORITY,
name?: string
): void {
if (this.isShuttingDown) {
return;
}
this.callbacks.push({ callback, priority, name });
}
@ -42,14 +48,16 @@ export class Shutdown {
* Initiate graceful shutdown
*/
async shutdown(): Promise<void> {
if (this.isShuttingDown) { return };
if (this.isShuttingDown) {
return;
}
this.isShuttingDown = true;
const timeout = new Promise<never>((_, reject) =>
const timeout = new Promise<never>((_, reject) =>
setTimeout(() => reject(new Error('Shutdown timeout')), this.shutdownTimeout)
);
try {
await Promise.race([this.executeCallbacks(), timeout]);
} catch (error) {
@ -60,7 +68,7 @@ export class Shutdown {
private async executeCallbacks(): Promise<void> {
const sorted = [...this.callbacks].sort((a, b) => a.priority - b.priority);
for (const { callback, name } of sorted) {
try {
await callback();
@ -71,10 +79,12 @@ export class Shutdown {
}
private setupSignalHandlers(): void {
if (this.signalHandlersRegistered) { return };
if (this.signalHandlersRegistered) {
return;
}
const signals: NodeJS.Signals[] = ['SIGTERM', 'SIGINT'];
signals.forEach(signal => {
process.once(signal, async () => {
if (!this.isShuttingDown) {
@ -87,7 +97,7 @@ export class Shutdown {
}
});
});
this.signalHandlersRegistered = true;
}
}
}