better error handling
This commit is contained in:
parent
41c1f38cdb
commit
241ff55062
1 changed files with 11 additions and 8 deletions
|
@ -1,4 +1,5 @@
|
|||
import asyncio
|
||||
import logging
|
||||
import socket
|
||||
import time
|
||||
from collections import namedtuple
|
||||
|
@ -9,7 +10,6 @@ from urllib.parse import urlparse
|
|||
import aiohttp
|
||||
import feedparser
|
||||
import psutil
|
||||
from aiohttp import ClientConnectorError
|
||||
from bs4 import BeautifulSoup
|
||||
from django.views.generic import TemplateView
|
||||
from humanize import naturalsize
|
||||
|
@ -17,6 +17,8 @@ from humanize import naturalsize
|
|||
from sdbs_infra import settings
|
||||
from sdbs_infra.dashboard.models import Service, Status, Link, Machine, Feed
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class IndexView(TemplateView):
|
||||
template_name = "index.html"
|
||||
|
@ -49,8 +51,8 @@ class IndexView(TemplateView):
|
|||
try:
|
||||
async with session.get(link.url) as response:
|
||||
index_status, index_text = response.status, await response.text()
|
||||
except (asyncio.TimeoutError, ClientConnectorError):
|
||||
pass
|
||||
except Exception as exc:
|
||||
logger.exception(exc)
|
||||
|
||||
image = link.image.url if link.image else self.extract_favicon(link.url, index_text)
|
||||
|
||||
|
@ -73,8 +75,8 @@ class IndexView(TemplateView):
|
|||
try:
|
||||
async with session.get(service.url) as response:
|
||||
index_status, index_text = response.status, await response.text()
|
||||
except (asyncio.TimeoutError, ClientConnectorError):
|
||||
pass
|
||||
except Exception as exc:
|
||||
logging.exception(exc)
|
||||
|
||||
if service.port:
|
||||
a_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
|
@ -121,8 +123,8 @@ class IndexView(TemplateView):
|
|||
'down': Status.DOWN
|
||||
}.get(check.get('status'), Status.UNKNOWN)
|
||||
last_ping = datetime.fromisoformat(check.get('last_ping'))
|
||||
except (asyncio.TimeoutError, ClientConnectorError):
|
||||
pass
|
||||
except Exception as exc:
|
||||
logger.exception(exc)
|
||||
|
||||
result.append({
|
||||
'status': status.value,
|
||||
|
@ -145,7 +147,8 @@ class IndexView(TemplateView):
|
|||
for entry in entries:
|
||||
entry.published_datetime = datetime(*entry.published_parsed[0:6])
|
||||
result.extend(parsed_feed.entries)
|
||||
except (asyncio.TimeoutError, ClientConnectorError):
|
||||
except Exception as exc:
|
||||
logger.exception(exc)
|
||||
continue
|
||||
|
||||
result.sort(key=itemgetter('published_parsed'), reverse=True)
|
||||
|
|
Loading…
Reference in a new issue