rabbitmq-enterprise-toolkit
Version:
🚀 Enterprise-grade RabbitMQ wrapper for Node.js & TypeScript - High-throughput messaging with automatic retry, DLQ, batch processing & graceful shutdown. Production-ready AMQP client with zero message loss guarantee.
36 lines • 1.15 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.GracefulShutdown = void 0;
class GracefulShutdown {
constructor(timeoutMs = 10000) {
this.timeoutMs = timeoutMs;
this.isShuttingDown = false;
this.shutdownPromise = null;
}
async shutdown() {
if (this.shutdownPromise) {
return this.shutdownPromise;
}
this.isShuttingDown = true;
this.shutdownPromise = this.createShutdownPromise();
return this.shutdownPromise;
}
isShutdownInProgress() {
return this.isShuttingDown;
}
createShutdownPromise() {
return new Promise((resolve) => {
const timer = setTimeout(() => {
console.warn(`Graceful shutdown timeout after ${this.timeoutMs}ms`);
resolve();
}, this.timeoutMs);
// Allow immediate shutdown if needed
process.nextTick(() => {
clearTimeout(timer);
resolve();
});
});
}
}
exports.GracefulShutdown = GracefulShutdown;
//# sourceMappingURL=graceful-shutdown.js.map