-
-
Notifications
You must be signed in to change notification settings - Fork 187
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
Getting lots of 429 rate limit errors on https://slack.com/api/rtm.start calls #242
Comments
What's the stack for that status? I would get a backtrace first for when this happens. Compare with https://github.com/slack-ruby/slack-ruby-bot-server/blob/0b8bbbba45a2b07f35b223b4c18ec86888fc0f49/lib/slack-ruby-bot-server/service.rb, you might be accidentally looping very quickly when you get disconnected and need to reconnect, or something like that. |
How do you suggest I get a backtrace? I have fixed my code to call |
Add a
That's possible. |
I will do that if I see the error again, and close this ticket otherwise. Thank you for your time. |
The error did not appear again, so it was me calling an extra: client = SlackRubyBot::Client.new(token: ENV['SLACK_API_TOKEN'])
client.start_async for background jobs, and letting it getting GC'd witout further action. This would make clients pile up and eventually getting rate limited when they all tried reconnecting. While in fact I should have called this when I was done with temporary clients: client.stop! I now use an ensure block like so: def self.with_client_and_data_or_new(client, data)
if client.nil? || data.nil?
begin
client = self.get_new_client
channel = self.get_channel_by_name(client, 'any_chan_name')
data = self.wrap_in_data_object(channel: channel.id,
user: MY_BOT_USERID)
yield(client, data)
ensure
client.stop!
client = nil
end
else
yield(client, data)
end
end
private
def self.get_channel_by_name(client, channel_name)
client
&.channels
&.select { |k, chan| chan['name'] == channel_name }
&.map { |id, info| info }
&.first
end
def self.wrap_in_data_object(channel: nil, user: nil)
Hashie::Mash.new({ channel: channel, user: user})
end
def self.get_new_client
client = SlackRubyBot::Client.new(token: ENV['SLACK_API_TOKEN'])
client.start_async
10.times do
break if client.started?
sleep 1
end
sleep 1
client
end that I use like this: with_client_and_data_or_new(client, data) do |c, d|
# do something with c(lient) & d(ata)
end Is that a good approach or did I miss something obvious? |
Does your background job need an RTM client that's listening on Slack events? If you're trying to call some methods like listing channels, instantiate a |
Right, that looks like the obvious way to do it. Thank you. |
Hello,
I have been using this project for a while, and switched a couple months ago to async-websocket as recommended (for better reliability than Celluloid, which we had issues with indeed).
Recently, I have been getting more and more of these in the logs while the bot is idle:
My Gemfile has:
My bot is defined like this:
And I start the bot like this:
What could cause the rate limiting errors? Am I the only one with this issue?
I use this code to create a client for background tasks:
Maybe this is problematic?
The text was updated successfully, but these errors were encountered: