summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--lib/feed2imap/cache.rb16
-rw-r--r--lib/feed2imap/feed2imap.rb8
2 files changed, 22 insertions, 2 deletions
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