This commit is contained in:
parent
033a8b6534
commit
a43eaee8e0
|
@ -90,16 +90,18 @@ class ViewedStorage:
|
||||||
async def update_pages():
|
async def update_pages():
|
||||||
"""query all the pages from ackee sorted by views count"""
|
"""query all the pages from ackee sorted by views count"""
|
||||||
logger.info(" ⎧ updating ackee pages data ---")
|
logger.info(" ⎧ updating ackee pages data ---")
|
||||||
|
try:
|
||||||
start = time.time()
|
start = time.time()
|
||||||
self = ViewedStorage
|
self = ViewedStorage
|
||||||
if self.client:
|
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", [])
|
domains = self.pages.get("domains", [])
|
||||||
logger.debug(f" | domains: {domains}")
|
# logger.debug(f" | domains: {domains}")
|
||||||
for domain in domains:
|
for domain in domains:
|
||||||
pages = domain.get("statistics", {}).get("pages", [])
|
pages = domain.get("statistics", {}).get("pages", [])
|
||||||
if pages:
|
if pages:
|
||||||
logger.debug(f" | pages: {pages}")
|
# logger.debug(f" | pages: {pages}")
|
||||||
shouts = {}
|
shouts = {}
|
||||||
for page in pages:
|
for page in pages:
|
||||||
p = page["value"].split("?")[0]
|
p = page["value"].split("?")[0]
|
||||||
|
@ -112,6 +114,10 @@ class ViewedStorage:
|
||||||
end = time.time()
|
end = time.time()
|
||||||
logger.info(" ⎪ update_pages took %fs " % (end - start))
|
logger.info(" ⎪ update_pages took %fs " % (end - start))
|
||||||
|
|
||||||
|
except Exception:
|
||||||
|
import traceback
|
||||||
|
traceback.print_exc()
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
async def get_facts():
|
async def get_facts():
|
||||||
self = ViewedStorage
|
self = ViewedStorage
|
||||||
|
@ -119,7 +125,7 @@ class ViewedStorage:
|
||||||
try:
|
try:
|
||||||
if self.client:
|
if self.client:
|
||||||
async with self.lock:
|
async with self.lock:
|
||||||
facts = self.client.execute(load_facts)
|
facts = await self.client.execute(load_facts)
|
||||||
except Exception as er:
|
except Exception as er:
|
||||||
logger.error(f" - get_facts error: {er}")
|
logger.error(f" - get_facts error: {er}")
|
||||||
return facts or []
|
return facts or []
|
||||||
|
|
Loading…
Reference in New Issue
Block a user