Skip to content

Commit

Permalink
fix: gracefully remove consumer from redis on sigterm (#9252)
Browse files Browse the repository at this point in the history
* gracefully remove consumer from redis on sigterm

Signed-off-by: Matt Krick <matt.krick@gmail.com>

* fix: gracefully remove consumer from redis on sigterm

Signed-off-by: Matt Krick <matt.krick@gmail.com>

---------

Signed-off-by: Matt Krick <matt.krick@gmail.com>
  • Loading branch information
mattkrick committed Dec 7, 2023
1 parent b4821d2 commit fd273bb
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions packages/gql-executor/gqlExecutor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit fd273bb

Please sign in to comment.