From fd273bbe175e64bd5ccaa4eb842ef3daf205ef65 Mon Sep 17 00:00:00 2001 From: Matt Krick Date: Thu, 7 Dec 2023 13:57:57 -0800 Subject: [PATCH] fix: gracefully remove consumer from redis on sigterm (#9252) * gracefully remove consumer from redis on sigterm Signed-off-by: Matt Krick * fix: gracefully remove consumer from redis on sigterm Signed-off-by: Matt Krick --------- Signed-off-by: Matt Krick --- packages/gql-executor/gqlExecutor.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/packages/gql-executor/gqlExecutor.ts b/packages/gql-executor/gqlExecutor.ts index 594b5dbbdcf..2b2984bb971 100644 --- a/packages/gql-executor/gqlExecutor.ts +++ b/packages/gql-executor/gqlExecutor.ts @@ -27,6 +27,17 @@ const run = async () => { const subscriber = new RedisInstance('gql_sub') const executorChannel = GQLExecutorChannelId.join(SERVER_ID) + // on shutdown, remove consumer from the group + process.on('SIGTERM', async () => { + await publisher.xgroup( + 'DELCONSUMER', + ServerChannel.GQL_EXECUTOR_STREAM, + ServerChannel.GQL_EXECUTOR_CONSUMER_GROUP, + executorChannel + ) + process.exit() + }) + // subscribe to direct messages const onMessage = async (_channel: string, message: string) => { const {jobId, socketServerId, request} = JSON.parse(message) as PubSubPromiseMessage