-
Notifications
You must be signed in to change notification settings - Fork 637
WIP: Bot: support bubbling up rate limit info #573
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,8 @@ | |
| SlackClient = require "./client" | ||
| pkg = require "../package" | ||
|
|
||
| Events = require("@slack/client").CLIENT_EVENTS | ||
|
|
||
| class SlackBot extends Adapter | ||
|
|
||
| ###* | ||
|
|
@@ -39,6 +41,7 @@ class SlackBot extends Adapter | |
| @client.rtm.on "close", @close | ||
| @client.rtm.on "disconnect", @disconnect | ||
| @client.rtm.on "error", @error | ||
| @client.web.on Events.WEB.RATE_LIMITED, @rate_limited | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mistydemeo Here is a sample I used for verifying this implementation. module.exports = (robot) ->
web = robot.adapter.client.web
robot.hear /call a lot/i, (res) ->
for x in [1..100]
web.conversations.list().then (res) ->
robot.logger.info "#{res.ok} #{res.error}"
robot.on 'slack-rate-limit', (res) ->
robot.logger.info "Detected a rate-limited call #{res}"Does this really work for you? It doesn't work for me. The following is the error I get every time the Also, to utilize this, you need to always use Correct me if my understanding is wrong. |
||
| @client.rtm.on "authenticated", @authenticated | ||
| @client.onEvent @eventHandler | ||
|
|
||
|
|
@@ -206,9 +209,20 @@ class SlackBot extends Adapter | |
| error: (error) => | ||
| @robot.logger.error "Slack RTM error: #{JSON.stringify error}" | ||
| # Assume that scripts can handle slowing themselves down, all other errors are bubbled up through Hubot | ||
| # NOTE: should rate limit errors also bubble up? | ||
| if error.code isnt -1 | ||
| @robot.emit "error", error | ||
| else | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can't find any official documentation of the rate-limiting code, but this test indicates that code -1 is reliably rate limiting: https://github.com/slackapi/hubot-slack/blob/master/test/bot.coffee#L168-L171 |
||
| # The actual duration of the rate limit isn't exposed. :( | ||
| @rate_limited(-1) | ||
|
|
||
| ###* | ||
| # Bubbles up rate-limit info, allowing the bot to react | ||
| # | ||
| # @private | ||
| # @param {number seconds} | ||
| ### | ||
| rate_limited: (seconds) -> | ||
| @robot.emit "slack-rate-limit", seconds | ||
|
|
||
| ###* | ||
| # Incoming Slack event handler | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.