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