finished shutdown lib

This commit is contained in:
Bojan Kucera 2025-06-07 10:40:08 -04:00
parent 97dcd30223
commit 13c2f10db9
4 changed files with 213 additions and 28 deletions

View file

@ -1,6 +1,6 @@
# @stock-bot/shutdown
Graceful shutdown management library for Node.js applications in the Stock Bot platform.
Shutdown management library for Node.js applications in the Stock Bot platform.
## Features
@ -9,8 +9,8 @@ Graceful shutdown management library for Node.js applications in the Stock Bot p
- ✅ **Multiple Callbacks** - Register multiple cleanup functions
- ✅ **Timeout Protection** - Configurable shutdown timeout
- ✅ **Error Handling** - Failed callbacks don't block shutdown
- ✅ **Debug Logging** - Optional detailed logging
- ✅ **TypeScript Support** - Full type definitions
- ✅ **Zero Dependencies** - Lightweight and efficient
## Installation
@ -85,12 +85,11 @@ await shutdownAndExit('manual', 0);
#### Manual Instance Management
```typescript
import { GracefulShutdown } from '@stock-bot/shutdown';
import { Shutdown } from '@stock-bot/shutdown';
const shutdown = new GracefulShutdown({
const shutdown = new Shutdown({
timeout: 20000,
autoRegister: true,
debug: true
autoRegister: true
});
shutdown.onShutdown(async () => {
@ -107,7 +106,6 @@ const result = await shutdown.shutdown('manual');
interface ShutdownOptions {
timeout?: number; // Timeout in ms (default: 30000)
autoRegister?: boolean; // Auto-register signals (default: true)
debug?: boolean; // Enable debug logging (default: false)
}
```
@ -150,9 +148,7 @@ onShutdown(async () => {
### Worker Process
```typescript
import { onShutdown, setShutdownDebug } from '@stock-bot/shutdown';
setShutdownDebug(true); // Enable debug logging
import { onShutdown } from '@stock-bot/shutdown';
let isRunning = true;