Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: gracefully remove consumer from redis on sigterm #9252

Merged
merged 5 commits into from
Dec 7, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't find any info if this method can potentially throw, if not we're good!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it shouldn't, unless redis is unreachable! but tbh this is just one of those nice-to-haves. if SIGKILL gets called after this fails it's not the end of the world

'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
Loading