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

View File

@ -1,13 +1,9 @@
FROM python:3.8 FROM python:3.10
EXPOSE 8080 EXPOSE 8080
ADD nginx.conf.sigil ./
RUN /usr/local/bin/python -m pip install --upgrade pip RUN /usr/local/bin/python -m pip install --upgrade pip
WORKDIR /usr/src/app WORKDIR /usr/src/app
COPY requirements.txt ./ COPY requirements.txt ./
RUN set -ex && pip install -r requirements.txt RUN set -ex && pip install -r requirements.txt
COPY . . COPY . .

View File

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