Skip to main content

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

  1. Ensure that NestJS shutdown hooks are enabled in your main.ts file:
const app = await NestFactory.create(AppModule);
...
app.enableShutdownHooks();
  1. Set the k8s terminationGracePeriodSeconds in your deployment to at least SHUTDOWN_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 variableDefault.Description
SHUTDOWN_MAX_DURATION_MS600000 (10 min)How long to wait for in-flight jobs before proceeding with shutdown