From 06f232fdd8a99011ab26b2d5eff0105990225943 Mon Sep 17 00:00:00 2001 From: Mononaut Date: Tue, 2 Aug 2022 01:46:23 +0000 Subject: [PATCH] handle SIGTERM gracefully in unfurler --- unfurler/src/index.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/unfurler/src/index.ts b/unfurler/src/index.ts index d84ce883a..089c9a280 100644 --- a/unfurler/src/index.ts +++ b/unfurler/src/index.ts @@ -48,6 +48,16 @@ class Server { }); } + async stopServer() { + if (this.cluster) { + await this.cluster.idle(); + await this.cluster.close(); + } + if (this.server) { + await this.server.close(); + } + } + setUpRoutes() { this.app.get('/render*', async (req, res) => { return this.renderPreview(req, res) }) this.app.get('*', (req, res) => { return this.renderHTML(req, res) }) @@ -133,3 +143,9 @@ class Server { } const server = new Server(); + +process.on('SIGTERM', async () => { + console.info('Shutting down Mempool Unfurl Server'); + await server.stopServer(); + process.exit(0); +});