slack-ruby-client icon indicating copy to clipboard operation
slack-ruby-client copied to clipboard

Recover messages when on disconnection

Open MarioRuiz opened this issue 4 years ago • 7 comments

Add an option to automatically recover messages sent during the time has been auto disconnected from slack.

MarioRuiz avatar Mar 24 '20 14:03 MarioRuiz

You mean build-in retry? What's your scenario? Are we talking RTM or Web API?

dblock avatar Mar 24 '20 14:03 dblock

RTM. Not a retry but to recover the messages we missed during the time was disconnected. Sometimes the connection is disconnected for a second or a little longer and if we are not lucky and a message was sent during that time, the bot will never respond, even though the connection will be recovered in a second.

MarioRuiz avatar Mar 25 '20 12:03 MarioRuiz

I see. I could be wrong, but I don't think Slack provides that kind of facility.

dblock avatar Mar 25 '20 12:03 dblock

We could try an exponential backoff, synchronously. Something like this

number_of_retries = 3 backoff_factor = 2 attempt = 1

First attempt after 2 seconds. [attempt] Second attempt after 22 (4) seconds. [attempt x backoff_factor] Third attempt after 42(8) seconds. [attempt x backoff_factor] Finally return result (Success/failure) The api would return only after all the retries have been completed.

But I don't know if this would be overkill. Considering that the gem returns an error response, the apps using this gem could implement this functionality.

dinesh-hd avatar Sep 02 '20 06:09 dinesh-hd

I think the issue describes recovering incoming RTM messages that were missed, not retrying API calls (that is more standard in client libraries and I'd be open to having that implemented via https://www.rubydoc.info/github/lostisland/faraday/Faraday/Request/Retry).

dblock avatar Sep 02 '20 15:09 dblock

Just to clarify this is the case using the client.on :close, client.on :closed, client.on :hello [2020-09-28T16:24:08.723056 #17096] INFO -- : Connection closing, exiting. 2020-09-28 16:24:08 +0000 [2020-09-28T16:24:08.723391 #17096] INFO -- : Connection has been disconnected. 2020-09-28 16:24:08 +0000 [2020-09-28T16:24:10.113424 #17096] INFO -- : Successfully connected, welcome 'smart-bot' to the 'xxxxxx' team at https://xxxxxx.slack.com.

So a couple of seconds where the Bot was disconnected, so not listening and if during that time a user sent a message the bot won't be aware of that message and won't respond.
I am facing this kind of disconnections like 10 times every day. So if we would be aware of the last message received and then on :hello we recover all messages sine last connection we can filter the ones that were sent during the disconnection.

MarioRuiz avatar Sep 29 '20 13:09 MarioRuiz

I don't know of a way to recover those messages :(

This is one of the reasons to switch from an RTM solution to an event-based one (using https://github.com/slack-ruby/slack-ruby-bot-server-events), where Slack will queue messages if your application is not able to respond.

dblock avatar Sep 29 '20 15:09 dblock