This commit is contained in:
2022-11-28 17:55:30 +03:00
parent d8c293a56e
commit 84926b6110
2 changed files with 7 additions and 11 deletions

View File

@@ -84,12 +84,12 @@ class ViewedStorage:
@staticmethod
async def update_pages():
""" query all the pages from ackee sorted by views count """
print("[stat.viewed] ⎧ updating ackee pages data ---")
start = time.time()
self = ViewedStorage
try:
self.pages = await self.client.execute_async(load_pages)
self.pages = self.pages["domains"][0]["statistics"]["pages"]
print("[stat.viewed] ⎪ ackee pages updated")
shouts = {}
try:
for page in self.pages:
@@ -179,14 +179,14 @@ class ViewedStorage:
async with self.lock:
while True:
try:
print("[stat.viewed] updating views...")
print("[stat.viewed] - updating views...")
await self.update_pages()
failed = 0
except Exception:
failed += 1
print("[stat.viewed] update failed #%d, wait 10 seconds" % failed)
print("[stat.viewed] - update failed #%d, wait 10 seconds" % failed)
if failed > 3:
print("[stat.viewed] not trying to update anymore")
print("[stat.viewed] - not trying to update anymore")
break
if failed == 0:
when = datetime.now(timezone.utc) + timedelta(seconds=self.period)
@@ -197,4 +197,4 @@ class ViewedStorage:
await asyncio.sleep(self.period)
else:
await asyncio.sleep(10)
print("[stat.viewed] trying to update data again...")
print("[stat.viewed] - trying to update data again")