lower service timeout to 2, put both in a class constant

This commit is contained in:
Tomáš Mládek 2020-09-15 21:02:38 +02:00
parent d65e92e323
commit 054b18b593

View file

@ -23,6 +23,9 @@ logger = logging.getLogger(__name__)
class IndexView(TemplateView): class IndexView(TemplateView):
template_name = "index.html" template_name = "index.html"
SERVICE_TIMEOUT = 2
REQ_TIMEOUT = 5
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
return { return {
'vps_stats': self.vps_stats(), 'vps_stats': self.vps_stats(),
@ -47,7 +50,7 @@ class IndexView(TemplateView):
async def process_links(self, links): async def process_links(self, links):
result = [] result = []
session = aiohttp.ClientSession(timeout=aiohttp.ClientTimeout(total=5, sock_connect=1)) session = aiohttp.ClientSession(timeout=aiohttp.ClientTimeout(total=self.REQ_TIMEOUT, sock_connect=1))
for link in links: for link in links:
index_text = None index_text = None
@ -71,7 +74,7 @@ class IndexView(TemplateView):
async def process_services(self, services): async def process_services(self, services):
result = [] result = []
session = aiohttp.ClientSession(timeout=aiohttp.ClientTimeout(total=3, sock_connect=1)) session = aiohttp.ClientSession(timeout=aiohttp.ClientTimeout(total=self.SERVICE_TIMEOUT, sock_connect=1))
for service in services: for service in services:
index_status, index_text = None, None index_status, index_text = None, None
@ -109,7 +112,7 @@ class IndexView(TemplateView):
async def process_machines(self, machines): async def process_machines(self, machines):
result = [] result = []
session = aiohttp.ClientSession(timeout=aiohttp.ClientTimeout(total=5, sock_connect=1), headers={ session = aiohttp.ClientSession(timeout=aiohttp.ClientTimeout(total=self.REQ_TIMEOUT, sock_connect=1), headers={
'X-Api-Key': settings.HEALTCHECKS_API_KEY 'X-Api-Key': settings.HEALTCHECKS_API_KEY
}) })
@ -141,7 +144,7 @@ class IndexView(TemplateView):
async def process_feeds(self, feeds): async def process_feeds(self, feeds):
result = [] result = []
session = aiohttp.ClientSession(timeout=aiohttp.ClientTimeout(total=5, sock_connect=1)) session = aiohttp.ClientSession(timeout=aiohttp.ClientTimeout(total=self.REQ_TIMEOUT, sock_connect=1))
for feed in feeds: for feed in feeds:
try: try: