Skip to content

Commit

Permalink
Join ConsumerGroup synchronously
Browse files Browse the repository at this point in the history
At the moment there is a race going on between when the consumer starts
and when the shard dispatches the first events. For bots that do things
like loading commands on READY, sometimes they may not do it at all as
the consumer is not subscribed and running yet when the shard comes up.
A proper fix for this would be starting the Consumer before the shard,
but with the current architecture of having the consumer in the client
app but not the shard, no synchronized startup procedure is possible
here (unless we add some form of
make-the-shard-wait-for-the-consumer-to-tell-it-that-it-is-up feature,
which I would claim is a bit hacky).
  • Loading branch information
jchristgit committed May 31, 2023
1 parent 5ec6ec5 commit 5e8dd37
Showing 1 changed file with 1 addition and 6 deletions.
7 changes: 1 addition & 6 deletions lib/nostrum/consumer.ex
Original file line number Diff line number Diff line change
Expand Up @@ -408,13 +408,8 @@ defmodule Nostrum.Consumer do

@impl GenServer
def init([]) do
{:ok, nil, {:continue, nil}}
end

@impl GenServer
def handle_continue(_args, state) do
ConsumerGroup.join(self())
{:noreply, state}
{:ok, nil}
end

@impl GenServer
Expand Down

0 comments on commit 5e8dd37

Please # to comment.