Changeset 264

Show
Ignore:
Timestamp:
05/20/06 12:28:29 (3 years ago)
Author:
stillflame
Message:

- mode the TracPlugin? more fault tolerant and robust

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/tools/irc/trac.rb

    r263 r264  
    2828require 'rss/2.0' 
    2929require 'open-uri' 
     30require 'timeout' 
    3031require 'yaml' 
    3132 
     
    4142        @feeds = {} 
    4243        @period = 60 
     44        @time_limit = 5 
     45        @retry_limit = 5 
    4346        @bot.timer.add( @period, self ) { |tracer| 
    4447            tracer.feed 
     
    4750 
    4851    def feed 
    49         puts @feeds.to_yaml 
    5052        @feeds.each {|url,params| 
     53            tries = 0 
    5154            begin 
    52                 open( url ) {|page| 
    53                     data = page.read 
    54                     @bot.say params[:where], parse( data, params ) 
     55                Timeout::timeout( @time_limit ) { 
     56                    open( url ) {|page| 
     57                        data = page.read 
     58                        @bot.say params[:where], parse( data, params ) 
     59                    } 
    5560                } 
    5661            rescue OpenURI::HTTPError, EOFError 
    57                 retry         #:MC: is this going to be really bad, like, if the connection goes down? 
     62                tries += 1 
     63                retry unless tries >= @retry_limit 
     64            rescue RSS::NotWellFormedError, SocketError, Timeout::Error 
     65                # just let these errors slide, but don't retry 
    5866            end 
    5967        }