vendure-ecommerce / vendure

The commerce platform with customization in its DNA.
https://www.vendure.io
Other
5.44k stars 964 forks source link

Does Vendure supports gracefully shutdowns? #2474

Open Zizitto opened 9 months ago

Zizitto commented 9 months ago

https://cloud.google.com/run/docs/samples/cloudrun-sigterm-handler

Our Vendure server is deployed via Cloud Run, worker is deployed via Kubernetes.

Both deployments from time to time receive SIGTERM signals. (during deployment of some changes or scale-downs).

Looks like HTTP requests and jobs processing are terminating immediately, which causes data inconsistency issues.

Can somebody check if Vendure supports gracefully shutdowns?

michaelbromley commented 9 months ago

Hi,

Since Vendure is built on NestJS, it handles graceful shutdowns the same way, described here: https://docs.nestjs.com/fundamentals/lifecycle-events#application-shutdown

The specific issue of requests being terminated is discussed in this issue: https://github.com/nestjs/nest/issues/11416 - it seems like it is something that needs to be addressed in NestJS itself.

As for jobs that are being processed - here's what happens:

  1. The onModuleDestroy() hook here is called, which invokes and awaits stop() on all running job queues.
  2. This in turn calls the stop() method of the configured JobQueueStrategy. This can therefore be configured to the desired behaviour. The default strategy in the DefaultJobQueuePlugin, for instance, will execute this logic that waits 2 seconds for running jobs to complete.