slack-ruby-bot: pongbot does not reconnect

Hi, I’m playing with your slack-ruby-bot in my holiday. I started from pongbot in README and talked with the bot, it’s πŸ‘

However, after several minutes of network disconnection, I noticed that pongbot does not try to reconnect to Slack.

For example, turn-off my WiFi network, wait several minutes, and then reconnect WiFi, pongbot is left disconnected even if WiFi is back. Terminal does not print any line during that experiment.

I believe handle_exceptions in server.rb kicks restart!. However, it seems not to catch any exception in this situation. Any hint to add reconnect feature to pongbot ?

I’m using Ruby 2.3.3 and macOS Sierra and slack-ruby-bot 0.9. Here is the Gemfile.lock for the pongbot

GEM
  remote: https://rubygems.org/
  specs:
    activesupport (5.0.1)
      concurrent-ruby (~> 1.0, >= 1.0.2)
      i18n (~> 0.7)
      minitest (~> 5.1)
      tzinfo (~> 1.1)
    celluloid (0.17.3)
      celluloid-essentials
      celluloid-extras
      celluloid-fsm
      celluloid-pool
      celluloid-supervision
      timers (>= 4.1.1)
    celluloid-essentials (0.20.5)
      timers (>= 4.1.1)
    celluloid-extras (0.20.5)
      timers (>= 4.1.1)
    celluloid-fsm (0.20.5)
      timers (>= 4.1.1)
    celluloid-io (0.17.3)
      celluloid (>= 0.17.2)
      nio4r (>= 1.1)
      timers (>= 4.1.1)
    celluloid-pool (0.20.5)
      timers (>= 4.1.1)
    celluloid-supervision (0.20.6)
      timers (>= 4.1.1)
    concurrent-ruby (1.0.4)
    faraday (0.10.1)
      multipart-post (>= 1.2, < 3)
    faraday_middleware (0.10.1)
      faraday (>= 0.7.4, < 1.0)
    gli (2.14.0)
    hashie (3.4.6)
    hitimes (1.2.4)
    i18n (0.7.0)
    json (2.0.2)
    minitest (5.10.1)
    multipart-post (2.0.0)
    nio4r (2.0.0)
    slack-ruby-bot (0.9.0)
      hashie
      slack-ruby-client (>= 0.6.0)
    slack-ruby-client (0.7.7)
      activesupport
      faraday
      faraday_middleware
      gli
      hashie
      json
      websocket-driver
    thread_safe (0.3.5)
    timers (4.1.2)
      hitimes
    tzinfo (1.2.2)
      thread_safe (~> 0.1)
    websocket-driver (0.6.4)
      websocket-extensions (>= 0.1.0)
    websocket-extensions (0.1.2)

PLATFORMS
  ruby

DEPENDENCIES
  celluloid-io
  slack-ruby-bot

BUNDLED WITH
   1.13.6

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 17

Most upvoted comments

To tell the truth, my first version was very similar to @gsmetal 's one like below. But I noticed that waiting pong was over-killing for my case.

class PingThread  < SlackRubyBot::Server
  extend Celluloid

  PONG_ID_QUEUE = []

  def self.pong_received?(id)
    !PONG_ID_QUEUE.delete(id).nil?
  end

  on 'hello' do |client, data|
    puts "Ping Thread HELLO!"
    PONG_ID_QUEUE.clear
    @reconnect_count ||= 0

    if @timer
      @timer.cancel
      @reconnect_count += 1
    end

    sequence = 1

    @timer = every 30 do
      client.ping({id: sequence})
      puts "ping #{sequence}, reconnect: #{@reconnect_count}."
      sleep 3
      raise Errno::ETIMEDOUT unless pong_received?(sequence)
      sequence += 1
    end
  end

  on 'pong' do |client, data|
    sequence = data[:reply_to].to_i
    puts "pong #{sequence}"
    PONG_ID_QUEUE << sequence
  end
end