Skip to content

Sandboxed workers: best way to setup DI container with long running TCP connections in services (like DB connection, Redis connection, etc.) #942

Answered by manast
tolgap asked this question in Q&A
Discussion options

You must be logged in to vote

I think the best is to create your connection outside of the processor so that it gets reused every time the process function is called, and then close the connection on the SIGINT event listener for the process:

process.on('SIGINT', await function () {
    await connection.close();
    process.exit();
  });

https://nodejs.org/api/process.html#signal-events

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@tolgap
Comment options

Answer selected by tolgap
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants