]> kaliko git repositories - sid.git/blobdiff - sid/feeds.py
feeds: catch ConnectionError to avoid killing thread
[sid.git] / sid / feeds.py
index 64ddf1217300b548ded94d947a14cc22aba3b9af..490d89de5816b230b5f3b91dc0f2afb5ffb5c548 100644 (file)
@@ -1,6 +1,6 @@
 # -*- coding: utf-8 -*-
 
-# Copyright (C) 2011, 2014 kaliko <kaliko@azylum.org>
+# Copyright (C) 2011, 2014, 2020 kaliko <kaliko@azylum.org>
 
 # This program is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -19,6 +19,8 @@ import threading
 import time
 import traceback
 
+from urllib.error import URLError
+
 from feedparser import parse as feed_parse
 
 from .plugin import Plugin, botcmd
@@ -122,7 +124,11 @@ class FeedMonitor(threading.Thread):
             for feed in self.feeds_list:
                 try:
                     self.new_posts(feed)
-                except Exception as err:
+                except ConnectionError as err:  # Non fatal exception
+                    self.plugin.log.error(f'connection error on {feed}: {err}')
+                except URLError as err:  # Non fatal exception
+                    self.plugin.log.error(f'error for {feed}: {err.reason}')
+                except Exception as err:  # Unknown execption, killing thread anyway
                     self.plugin.log.error('feeds thread crashed: %s', err)
                     self.plugin.log.error(''.join(traceback.format_exc()))
                     self.thread_killed = True
@@ -134,7 +140,14 @@ class FeedMonitor(threading.Thread):
 
 
 class Feeds(Plugin):
+    """
+    .. note::
+      Feeds plugin depends on external module: **feedparser**
+    """
+
+    #: Time between feeds check
     TEMPO = 60
+    #: Default feeds to monitor
     FEEDS = [
         'https://www.debian.org/security/dsa',
         'https://www.debian.org/News/news',
@@ -156,9 +169,10 @@ class Feeds(Plugin):
 
     @botcmd
     def feeds(self, rcv, args):
-        """feeds monitors debian project related feeds.
-        !feeds : registred feeds list
-        !feeds last : last check time"""
+        """Monitors debian project related feeds.
+
+        * ``!feeds``      : registred feeds list
+        * ``!feeds last`` : last check time"""
         if 'last' in args:
             self.reply(rcv, 'Last feeds check: %s' % self.th_mon.last_check)
             return