Comments (7)
Right, that looks like the obvious way to do it. Thank you.
from slack-ruby-bot.
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.
from slack-ruby-bot.
How do you suggest I get a backtrace?
I have fixed my code to call stop!
after I'm done with a new client, maybe that will solve the issue.
Maybe the clients never got GC'd and I'd increasingly had more and more clients connecting.
from slack-ruby-bot.
How do you suggest I get a backtrace?
Add a begin/rescue
around start_async
to begin with, but otherwise find where that message is emitted from and walk backwards from there to see what calls it, etc.
I have fixed my code to call
stop!
after I'm done with a new client, maybe that will solve the issue.
Maybe the clients never got GC'd and I'd increasingly had more and more clients connecting.
That's possible.
from slack-ruby-bot.
I will do that if I see the error again, and close this ticket otherwise. Thank you for your time.
from slack-ruby-bot.
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?
from slack-ruby-bot.
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 Slack::Web::Client.new(token: ...)
and call whatever you need. There will be nothing to shutdown.
from slack-ruby-bot.
Related Issues (20)
- Graceful shutdown HOT 1
- Testing other code execution inside a command HOT 8
- Deployment tutorial needs update HOT 2
- DMing self produces Sorry @Slackbot, I don't understand that command! HOT 1
- Migration to non-legacy bots HOT 6
- Consider splitting RSpec shared behaviours and development dependencies HOT 4
- Where can i find more info on the client.say method? HOT 7
- Remove support for Giphy
- Extract attachments text
- without mention in channel bot can't reply HOT 1
- Upload a file? HOT 1
- Pongbot does not run on linux mint 19 HOT 4
- Testing for two outputs from a command HOT 5
- When a command is posted in thread, its again posted as direct message automatically HOT 4
- is there an example for how to implement a conversational bot using slack-ruby-bot? HOT 1
- Missing concurrency - Add faye-websocket to your gemfile -- It's already in my Gemfile HOT 1
- Clarification of MIGRATION.md HOT 8
- Is this repo really legacy, there is still a use case? HOT 3
- Repeated 429 (ratelimited) errors from slack HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from slack-ruby-bot.