lib/slack/real_time/client.rb in slack-ruby-client-0.14.2 vs lib/slack/real_time/client.rb in slack-ruby-client-0.14.3
- old
+ new
@@ -80,22 +80,22 @@
end
def run_loop
@socket.connect! do |driver|
driver.on :open do |event|
- logger.debug("#{self.class}##{__method__}") { event.class.name }
+ logger.debug("#{self}##{__method__}") { event.class.name }
open(event)
callback(event, :open)
end
driver.on :message do |event|
- logger.debug("#{self.class}##{__method__}") { "#{event.class}, #{event.data}" }
+ logger.debug("#{self}##{__method__}") { "#{event.class}, #{event.data}" }
dispatch(event)
end
driver.on :close do |event|
- logger.debug("#{self.class}##{__method__}") { event.class.name }
+ logger.debug("#{self}##{__method__}") { event.class.name }
callback(event, :close)
close(event)
callback(event, :closed)
end
@@ -125,21 +125,34 @@
# Check if the remote server is responsive, and if not, restart the connection.
def run_ping!
return if keep_alive?
+ logger.warn(to_s) { 'is offline' }
+
restart_async
+ rescue StandardError => e
+ # disregard all ping worker failures, keep pinging
+ logger.debug("#{self}##{__method__}") { e }
end
def run_ping?
!websocket_ping.nil? && websocket_ping > 0
end
+ def to_s
+ if store && store.team
+ "id=#{store.team.id}, name=#{store.team.name}, domain=#{store.team.domain}"
+ else
+ super
+ end
+ end
+
protected
def restart_async
- logger.debug("#{self.class}##{__method__}")
+ logger.debug("#{self}##{__method__}")
@socket.close
start = web_client.send(rtm_start_method, start_options)
data = Slack::Messages::Message.new(start)
@url = data.url
@store = @store_class.new(data) if @store_class
@@ -181,11 +194,11 @@
end
def send_json(data)
raise ClientNotStartedError unless started?
- logger.debug("#{self.class}##{__method__}") { data }
+ logger.debug("#{self}##{__method__}") { data }
@socket.send_data(data.to_json)
end
def open(_event); end
@@ -202,11 +215,11 @@
callbacks.each do |c|
c.call(event)
end
true
rescue StandardError => e
- logger.error e
+ logger.error("#{self}##{__method__}") { e }
false
end
def dispatch(event)
return false unless event.data
@@ -214,15 +227,15 @@
data = Slack::Messages::Message.new(JSON.parse(event.data))
type = data.type
return false unless type
type = type.to_s
- logger.debug("#{self.class}##{__method__}") { data.to_s }
+ logger.debug("#{self}##{__method__}") { data.to_s }
run_handlers(type, data) if @store
run_callbacks(type, data)
rescue StandardError => e
- logger.error e
+ logger.error("#{self}##{__method__}") { e }
false
end
def run_handlers(type, data)
handlers = store.class.events[type.to_s]
@@ -230,11 +243,11 @@
handlers.each do |handler|
store.instance_exec(data, &handler)
end
end
rescue StandardError => e
- logger.error e
+ logger.error("#{self}##{__method__}") { e }
false
end
def run_callbacks(type, data)
callbacks = self.callbacks[type]
@@ -243,10 +256,10 @@
callbacks.each do |c|
c.call(data)
end
true
rescue StandardError => e
- logger.error e
+ logger.error("#{self}##{__method__}") { e }
false
end
end
end
end