Graceful shutdown with Node.js Background Processes

Viewed 19

I have a Node.js HTTP Server running that also performs some background tasks. When I perform graceful shutdown, the HTTP requests are catered to well, but the background tasks stop abruptly and don't run to completion.

I have a Nats event queue that listens to events and performs necessary actions when an event is received. Before shutting down, I perform a nc.drain operation but I believe this only ensures that all messages are received, and not that all messages are "processed".

How do I make sure all events are processed before the server is shutdown?

0 Answers
Related