Class: SlackRubyBotServer::RealTime::Server
- Inherits:
-
SlackRubyBot::Server
- Object
- SlackRubyBot::Server
- SlackRubyBotServer::RealTime::Server
- Defined in:
- lib/slack-ruby-bot-server-rtm/server.rb
Instance Attribute Summary collapse
-
#team ⇒ Object
Returns the value of attribute team.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(attrs = {}) ⇒ Server
constructor
A new instance of Server.
- #restart!(_wait = 1) ⇒ Object
Constructor Details
#initialize(attrs = {}) ⇒ Server
Returns a new instance of Server.
10 11 12 13 14 15 16 17 18 |
# File 'lib/slack-ruby-bot-server-rtm/server.rb', line 10 def initialize(attrs = {}) attrs = attrs.dup @team = attrs.delete(:team) raise 'Missing team' unless @team attrs[:token] = @team.token super(attrs) open! end |
Instance Attribute Details
#team ⇒ Object
Returns the value of attribute team.
8 9 10 |
# File 'lib/slack-ruby-bot-server-rtm/server.rb', line 8 def team @team end |
Class Method Details
.start_server!(team, server, wait = 1) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/slack-ruby-bot-server-rtm/server.rb', line 20 def self.start_server!(team, server, wait = 1) team.server = server server.start_async rescue StandardError => e SlackRubyBotServer::Config.service_class.instance.send(:run_callbacks, :error, team, e) case e. when 'account_inactive', 'invalid_auth' then SlackRubyBotServer::Config.service_class.instance.logger.error "#{team.name}: #{e.}, team will be deactivated." SlackRubyBotServer::Config.service_class.instance.deactivate! team else wait = e.retry_after if e.is_a?(Slack::Web::Api::Errors::TooManyRequestsError) SlackRubyBotServer::Config.service_class.instance.logger.error "#{team.name}: #{e.}, restarting in #{wait} second(s)." sleep(wait) start_server! team, server, [wait * 2, 60].min end end |
Instance Method Details
#restart!(_wait = 1) ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/slack-ruby-bot-server-rtm/server.rb', line 37 def restart!(_wait = 1) # when an integration is disabled, a live socket is closed, which causes the default behavior of the client to restart # it would keep retrying without checking for account_inactive or such, we want to restart via service which will disable an inactive team SlackRubyBotServer::Config.service_class.instance.logger.info "#{team.name}: socket closed, restarting ..." SlackRubyBotServer::Config.service_class.instance.restart! team open! end |