class MikuTwitter::StreamingFailedActions

Attributes

fail_count[R]
last_code[R]
wait_time[R]

Public Class Methods

new(name, plugin) click to toggle source
# File core/lib/mikutwitter/streaming_failed_actions.rb, line 7
def initialize(name, plugin)
  @name = name
  @plugin = plugin
  @last_code = '200'.freeze
  @wait_time = @fail_count = 0
end

Public Instance Methods

client_bug(res) click to toggle source

こちらの問題が原因でTwitterサーバからエラーが返って来ている場合の処理。 ただし、過去には何度もサーバ側の不具合で4xx系のエラーが返って来ていたことが あったのであまり宛てにするべきではない

Args

res

レスポンス(Net::HTTPResponse)

# File core/lib/mikutwitter/streaming_failed_actions.rb, line 61
def client_bug(res)
  Plugin.call(:streaming_connection_status_failed,
              @name, get_error_str(res)) end
flying_whale(e) click to toggle source

サーバエラー・過負荷時の処理

Args

e

レスポンス(Net::HTTPResponse)

# File core/lib/mikutwitter/streaming_failed_actions.rb, line 75
def flying_whale(e)
  Plugin.call(:streaming_connection_status_flying_whale,
              @name, get_error_str(res)) end
notify(e) click to toggle source
# File core/lib/mikutwitter/streaming_failed_actions.rb, line 14
def notify(e)
  if e.respond_to?(:code)
    if e.code != @last_code
      case e.code
      when '200'.freeze
        success
      when '401'.freeze         # unauthorized
        client_bug e
      when '403'.freeze         # forbidden
        client_bug e
      when '404'.freeze         # unknown
        client_bug e
      when '406'.freeze         # not accepptable
        client_bug e
      when '413'.freeze         # too long
        client_bug e
      when '416'.freeze         # range unacceptable
        client_bug e
      when '420'.freeze         # rate limited
        rate_limit e
      when '500'.freeze         # server internal error
        flying_whale e
      when '503'.freeze         # service overloaded
        flying_whale e
      end
    end
    httperror
    @last_code = e.code.freeze
  elsif e.is_a?(Exception) or e.is_a?(Thread)
    tcperror
  end
end
rate_limit(res) click to toggle source

規制された時の処理

Args

res

レスポンス(Net::HTTPResponse)

# File core/lib/mikutwitter/streaming_failed_actions.rb, line 68
def rate_limit(res)
  Plugin.call(:streaming_connection_status_ratelimit,
              @name, get_error_str(res)) end
success() click to toggle source

接続できた時の処理

Args

e

レスポンス(Net::HTTPResponse)

# File core/lib/mikutwitter/streaming_failed_actions.rb, line 50
def success
  Plugin.call(:streaming_connection_status_connected,
              @name, @last_code)
  @wait_time = @fail_count = 0
  @last_code = '200'.freeze end