summaryrefslogtreecommitdiff
path: root/data/rbot
diff options
context:
space:
mode:
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2006-07-26 13:05:28 +0000
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2006-07-26 13:05:28 +0000
commit066e89f089789753dd73e5a03e8b64e079f936ff (patch)
treee6cb17cb00774df24badcbdba18aa977ca8ee02a /data/rbot
parentd00ffdc589ac14fea4a89e1aebeb70046c3f5774 (diff)
More robust error handling in rss.rb, also increased the default polling value for feeds. If failures occurred, polling time is increased
Diffstat (limited to 'data/rbot')
-rw-r--r--data/rbot/plugins/rss.rb52
1 files changed, 29 insertions, 23 deletions
diff --git a/data/rbot/plugins/rss.rb b/data/rbot/plugins/rss.rb
index 353e1675..23f9f7e5 100644
--- a/data/rbot/plugins/rss.rb
+++ b/data/rbot/plugins/rss.rb
@@ -93,7 +93,7 @@ class RSSFeedsPlugin < Plugin
:desc => "How many characters to use of a RSS item text")
BotConfig.register BotConfigIntegerValue.new('rss.thread_sleep',
- :default => 120, :validate => Proc.new{|v| v > 30},
+ :default => 300, :validate => Proc.new{|v| v > 30},
:desc => "How many characters to use of a RSS item text")
@@watchThreads = Hash.new
@@ -355,6 +355,7 @@ class RSSFeedsPlugin < Plugin
debug "watcher for #{feed} started"
oldItems = []
firstRun = true
+ failures = 0
loop do
begin
debug "fetching #{feed}"
@@ -364,36 +365,38 @@ class RSSFeedsPlugin < Plugin
}
unless newItems
debug "no items in feed #{feed}"
- break
- end
- debug "Checking if new items are available for #{feed}"
- if firstRun
- debug "First run, we'll see next time"
- firstRun = false
+ failures +=1
else
- otxt = oldItems.map { |item| item.to_s }
- dispItems = newItems.reject { |item|
- otxt.include?(item.to_s)
- }
- if dispItems.length > 0
- debug "Found #{dispItems.length} new items in #{feed}"
- dispItems.each { |item|
- @@mutex.synchronize {
- printFormattedRss(feed, item)
- }
- }
+ debug "Checking if new items are available for #{feed}"
+ if firstRun
+ debug "First run, we'll see next time"
+ firstRun = false
else
- debug "No new items found in #{feed}"
+ otxt = oldItems.map { |item| item.to_s }
+ dispItems = newItems.reject { |item|
+ otxt.include?(item.to_s)
+ }
+ if dispItems.length > 0
+ debug "Found #{dispItems.length} new items in #{feed}"
+ dispItems.each { |item|
+ @@mutex.synchronize {
+ printFormattedRss(feed, item)
+ }
+ }
+ else
+ debug "No new items found in #{feed}"
+ end
end
+ oldItems = newItems.dup
end
- oldItems = newItems.dup
rescue Exception => e
- error "IO failed: #{e.inspect}"
+ error "Error watching #{feed}: #{e.inspect}"
debug e.backtrace.join("\n")
+ failures += 1
end
- seconds = @bot.config['rss.thread_sleep']
- seconds += seconds * rand(50)/100
+ seconds = @bot.config['rss.thread_sleep'] * (failures + 1)
+ seconds += seconds * (rand(100)-50)/100
debug "watcher for #{feed} going to sleep #{seconds} seconds.."
sleep seconds
end
@@ -441,6 +444,9 @@ class RSSFeedsPlugin < Plugin
rescue URI::InvalidURIError, URI::BadURIError => e
report_problem("invalid rss feed #{feed.url}", e, m)
return
+ rescue => e
+ report_problem("error getting #{feed.url}", e, m)
+ return
end
debug "fetched #{feed}"
unless xml