Repository navigation
Start message queues on demand - #18
Open
ryanwinchester wants to merge 2 commits into
Open
ryanwinchester wants to merge 2 commits into
ryanwinchester wants to merge 2 commits into
Conversation
The per-channel message queues only exist to keep send_message/2 to
Slack's rate limit of one message per second per channel, so they don't
need to be started for every conversation at startup. Start a channel's
queue the first time the bot sends to it instead.
- The bot no longer lists its conversations at startup, so it doesn't
need channels:read, groups:read, im:read or mpim:read for that, and
the ChannelServer and its join/leave tracking are gone.
- send_message/2 now works for any channel, including DMs by user ID
and channels joined after startup, which were silently dropped.
- A new queue sends its first message right away.
- send_message/2 logs an error and returns {:error, reason} when the
message can't be queued, instead of dropping it silently.
- The channels option is deprecated: it logs a warning and does nothing.
- Return an error instead of crashing the caller when the queue's supervisor isn't running, for example while it restarts. - Find a channel's queue by its registered name, which skips one that exited before the registry removed it, so the message isn't cast to a dead queue. - Only treat an ArgumentError from the registry reads as the registry not running. - Accept the bot struct in Slack.MessageServer.send/3 again. - Log a queue starting once, from init/1, at debug level. - Note that each channel or user ID has its own queue.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Supersedes #16, which came from @neilberkman's point that every bot has to list its conversations at startup, and needs
channels:read,groups:read,im:readandmpim:readfor that, even when it only sends DMs or handles interactions.#16 added
channels: falseto turn the channel server and the message queues off. But the queues only exist to keepsend_message/2to Slack's rate limit of one message per second per channel, and they don't need to know the bot's channels in advance. This starts a channel's queue the first time the bot sends to it, which removes the startup listing for every bot without an option, and keepssend_message/2working.Changes
Slack.MessageServer.send/3looks up the channel's queue, and starts it underSlack.DynamicSupervisorif there isn't one yet. Concurrent first sends share one queue.Slack.Supervisorkeeps the bot in the queue registry's metadata, so a queue can be started from just the bot module thatsend_message/2passes.Slack.ChannelServer, its registry, theusers.conversationslisting and themember_joined_channel/channel_lefthandling inSlack.Socketare removed. Those events still go tohandle_event/3.send_message/2logs an error and returns{:error, reason}when it can't queue the message (Slack.Supervisorisn't running, or the module isn't the bot), instead of dropping it silently.channelsoption is deprecated: it logs a warning and does nothing.channels:historyandchat:write, andmessage.channels.Behavior changes
send_message/2now sends to channels the bot didn't have a queue for, including DMs by user ID and channels joined after startup. Before, those messages were dropped without a trace.This also removes some channel server bugs: a restarted channel server crashed on queues that were still running, leaving a channel didn't stop its queue (the supervisor restarted it) and crashed for channels it wasn't tracking,
group_leftwasn't handled, and a message sent from amember_joined_channelhandler could arrive before the queue existed.Testing
mix compile --warnings-as-errors(dev and test),mix format --check-formatted,mix credo,mix dialyzerandmix test --warnings-as-errors(42 tests, 3 runs) on Elixir 1.15 / OTP 26, and the tests on Elixir 1.20 / OTP 29. Reverting each change makes a test fail.