ackee-load-fix
Some checks failed
deploy / deploy (push) Failing after 8s

This commit is contained in:
Untone 2024-01-13 15:57:35 +03:00
parent 033a8b6534
commit a43eaee8e0

View File

@ -90,16 +90,18 @@ class ViewedStorage:
async def update_pages():
"""query all the pages from ackee sorted by views count"""
logger.info(" ⎧ updating ackee pages data ---")
try:
start = time.time()
self = ViewedStorage
if self.client:
self.pages = self.client.execute(load_pages)
# Use asyncio.run to execute asynchronous code in the main entry point
self.pages = await asyncio.to_thread(self.client.execute, load_pages)
domains = self.pages.get("domains", [])
logger.debug(f" | domains: {domains}")
# logger.debug(f" | domains: {domains}")
for domain in domains:
pages = domain.get("statistics", {}).get("pages", [])
if pages:
logger.debug(f" | pages: {pages}")
# logger.debug(f" | pages: {pages}")
shouts = {}
for page in pages:
p = page["value"].split("?")[0]
@ -112,6 +114,10 @@ class ViewedStorage:
end = time.time()
logger.info(" ⎪ update_pages took %fs " % (end - start))
except Exception:
import traceback
traceback.print_exc()
@staticmethod
async def get_facts():
self = ViewedStorage
@ -119,7 +125,7 @@ class ViewedStorage:
try:
if self.client:
async with self.lock:
facts = self.client.execute(load_facts)
facts = await self.client.execute(load_facts)
except Exception as er:
logger.error(f" - get_facts error: {er}")
return facts or []