class Plugin::Streaming::PermaStreamer

Public Class Methods

new(service) click to toggle source

Args

service

接続するService

# File core/plugin/streaming/perma_streamer.rb, line 9
def initialize(service)
  @service = service
  @thread = Thread.new(&method(:mainloop))
  @fail = MikuTwitter::StreamingFailedActions.new('UserStream', Plugin.create(:streaming)) end

Public Instance Methods

kill() click to toggle source
# File core/plugin/streaming/perma_streamer.rb, line 43
def kill
  @thread.kill
end
mainloop() click to toggle source
# File core/plugin/streaming/perma_streamer.rb, line 14
def mainloop
  loop do
    begin
      streamer = Plugin::Streaming::Streamer.new(@service){
        @fail.success
      }
      result = streamer.thread.value
    rescue Net::ReadTimeout => exception
      @fail.notify(exception)
    rescue Net::HTTPError => exception
      warn "PermaStreamer caught exception"
      warn exception
      @fail.notify(exception)
    rescue Exception => exception
      warn "PermaStreamer caught exception"
      warn exception
      @fail.notify(exception)
    else
      notice "PermaStreamer exit"
      notice result
      @fail.notify(result)
    ensure
      streamer.kill if streamer
    end
    notice "retry wait #{@fail.wait_time}, fail_count #{@fail.fail_count}"
    sleep @fail.wait_time
  end
end