@synanetics/shutdown-delay-middleware
v2.0.0
Published
Shutdown delay middleware for MoleculerJS
Downloads
60
Maintainers
Keywords
Readme
@synanetics/shutdown-delay-middleware
Middleware for MoleculerJS to delay shutdown of services. Currently MoleculerJS context tracking shuts down each service when that service no longer has any MoleculerJS contexts assigned to it. This causes issues during shutdown where a service shuts down as it has no more contexts to process, but another service that depends on it still needs to call the service.
The Middleware alters this behaviour by instead setting a timeout to allow services to finish processing before procedding with shutdown.
The Middelware will only come into effect if the SIGTERM signal is emitted (e.g from K8S pod shutdown). If enabled and the SIGTERM signal is triggered, shutdown will be paused to allow any remaining requests to be processed before shutting down.
Usage
In your moleculer.config.js
file:
const { ShutdownDelayMiddleware } = require('@synanetics/shutdown-delay-middleware');
// or
import { ShutdownDelayMiddleware } from '@synanetics/shutdown-delay-middleware';
const config = {
// ... other MoleculerJS config
middlewares: [ShutdownDelayMiddleware({
// if enabled ShutdownDelayMiddleware will delay shutdown if the SIGTERM signal is received
enabled: true,
// Number of milliseconds to delay until proceeding with shutdown
shutdownTimeout: 10 * 1000,
})]
}