From 58be214e8ea62bf16d64161cf71079ee6e553816 Mon Sep 17 00:00:00 2001 From: lnu Date: Mon, 23 Oct 2006 16:30:31 +0000 Subject: adding parse failures git-svn-id: svn+ssh://svn.gna.org/svn/feed2imap/trunk/feed2imap@107 f70e237a-67f3-0310-a06c-d2b8a7116972 --- lib/feed2imap/cache.rb | 16 +++++++++++++++- lib/feed2imap/feed2imap.rb | 8 +++++++- 2 files changed, 22 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/feed2imap/cache.rb b/lib/feed2imap/cache.rb index 4687b76..00e6951 100644 --- a/lib/feed2imap/cache.rb +++ b/lib/feed2imap/cache.rb @@ -40,6 +40,7 @@ class ItemCache puts "GET_NEW_ITEMS FOR #{id}... (#{Time::now})" end @channels[id] ||= CachedChannel::new + @channels[id].parsefailures = 0 return @channels[id].get_new_items(items, always_new, ignore_hash) end @@ -69,6 +70,12 @@ class ItemCache @channels[id].fetch_failed end + # Parsing failure. + # returns number of failures + def parse_failed(id) + @channels[id].parse_failed + end + # Load the cache from an IO stream def load(io) begin @@ -110,7 +117,7 @@ class CachedChannel # 100 items should be enough for everybody, even quite busy feeds CACHESIZE = 100 - attr_accessor :lastcheck, :items, :failures + attr_accessor :lastcheck, :items, :failures, :parsefailures def initialize @lastcheck = Time::at(0) @@ -118,6 +125,7 @@ class CachedChannel @itemstemp = [] # see below @nbnewitems = 0 @failures = 0 + @parsefailures = 0 end # Let's explain @items and @itemstemp. @@ -234,6 +242,12 @@ class CachedChannel @items.length end + def parse_failed + @parsefailures = 0 if @parsefailures.nil? + @parsefailures += 1 + return @parsefailures + end + def fetch_failed @failures = 0 if @failures.nil? @failures += 1 diff --git a/lib/feed2imap/feed2imap.rb b/lib/feed2imap/feed2imap.rb index 2f62a80..7d67f8d 100644 --- a/lib/feed2imap/feed2imap.rb +++ b/lib/feed2imap/feed2imap.rb @@ -182,7 +182,13 @@ class Feed2Imap begin feed = FeedParser::Feed::new(f.body) rescue Exception => e - @logger.fatal("Error while parsing #{f.name}: #{e}") + n = @cache.parse_failed(feed.name) + m = "Error while parsing #{f.name}: #{e} (failed #{n} times)" + if n > @config.max_failures + @logger.fatal(m) + else + @logger.info(m) + end next end begin -- cgit v1.2.3-54-g00ecf