Graceful Shutdown
Ensure your project uses version 6.9.0 or higher of @picsart/pa-pluggable-workers-core.
Importing KafkaConsumerModule automatically enables graceful shutdown.
When a termination signal is received, the worker will:
- Stop consuming new messages from Kafka
- Wait for any in-flight jobs to finish
Setup
- Ensure that NestJS shutdown hooks are enabled in your
main.tsfile:
const app = await NestFactory.create(AppModule);
...
app.enableShutdownHooks();
- Set the k8s
terminationGracePeriodSecondsin your deployment to at leastSHUTDOWN_MAX_DURATION_MS/ 1000, otherwise k8s will SIGKILL the pod before shutdown completes.
If you have GracefullHook listed in your module's providers, remove it — it is deprecated and no longer needed.
Configuration
| Environment variable | Default. | Description |
|---|---|---|
SHUTDOWN_MAX_DURATION_MS | 600000 (10 min) | How long to wait for in-flight jobs before proceeding with shutdown |