This commit is contained in:
Tony Rewin 2023-10-06 05:33:51 +03:00
parent aa5709c695
commit 150449a0cf
3 changed files with 17 additions and 17 deletions

View File

@ -1,10 +1,10 @@
FROM python:slim FROM python:slim
WORKDIR /app WORKDIR /app
EXPOSE 8080 EXPOSE 80
# ADD nginx.conf.sigil ./ # ADD nginx.conf.sigil ./
COPY requirements.txt . COPY requirements.txt .
RUN apt update && apt install -y build-essential git RUN apt-get update && apt-get install -y build-essential git
ENV GIT_SSH_COMMAND "ssh -v" ENV GIT_SSH_COMMAND "ssh -v"
RUN pip install -r requirements.txt RUN pip install -r requirements.txt
COPY . . COPY . .

View File

@ -75,17 +75,17 @@ class ViewedStorage:
{"Authorization": "Bearer %s" % str(token)}, schema=schema_str {"Authorization": "Bearer %s" % str(token)}, schema=schema_str
) )
print( print(
"[stat.viewed] * authorized permanentely by ackee.discours.io: %s" "[stat] * authorized permanentely by ackee.discours.io: %s"
% token % token
) )
else: else:
print("[stat.viewed] * please set ACKEE_TOKEN") print("[stat] * please set ACKEE_TOKEN")
self.disabled = True self.disabled = True
@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 ---") print("[stat] ⎧ updating ackee pages data ---")
start = time.time() start = time.time()
self = ViewedStorage self = ViewedStorage
try: try:
@ -101,12 +101,12 @@ class ViewedStorage:
await ViewedStorage.increment(slug, shouts[slug]) await ViewedStorage.increment(slug, shouts[slug])
except Exception: except Exception:
pass pass
print("[stat.viewed] ⎪ %d pages collected " % len(shouts.keys())) print("[stat] ⎪ %d pages collected " % len(shouts.keys()))
except Exception as e: except Exception as e:
raise e raise e
end = time.time() end = time.time()
print("[stat.viewed] ⎪ update_pages took %fs " % (end - start)) print("[stat] ⎪ update_pages took %fs " % (end - start))
@staticmethod @staticmethod
async def get_facts(): async def get_facts():
@ -171,16 +171,16 @@ class ViewedStorage:
if viewer == "old-discours": if viewer == "old-discours":
# this is needed for old db migration # this is needed for old db migration
if shout.viewsOld == amount: if shout.viewsOld == amount:
print(f"viewsOld amount: {amount}") print(f"[stat] viewsOld amount: {amount}")
else: else:
print(f"viewsOld amount changed: {shout.viewsOld} --> {amount}") print(f"[stat] viewsOld amount changed: {shout.viewsOld} --> {amount}")
shout.viewsOld = amount shout.viewsOld = amount
else: else:
if shout.viewsAckee == amount: if shout.viewsAckee == amount:
print(f"viewsAckee amount: {amount}") print(f"[stat] viewsAckee amount: {amount}")
else: else:
print( print(
f"viewsAckee amount changed: {shout.viewsAckee} --> {amount}" f"[stat] viewsAckee amount changed: {shout.viewsAckee} --> {amount}"
) )
shout.viewsAckee = amount shout.viewsAckee = amount
@ -200,23 +200,23 @@ class ViewedStorage:
while True: while True:
try: try:
print("[stat.viewed] - updating views...") print("[stat] - 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] - update failed #%d, wait 10 seconds" % failed)
if failed > 3: if failed > 3:
print("[stat.viewed] - not trying to update anymore") print("[stat] - 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)
t = format(when.astimezone().isoformat()) t = format(when.astimezone().isoformat())
print( print(
"[stat.viewed] ⎩ next update: %s" "[stat] ⎩ next update: %s"
% (t.split("T")[0] + " " + t.split("T")[1].split(".")[0]) % (t.split("T")[0] + " " + t.split("T")[1].split(".")[0])
) )
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] - trying to update data again")

View File

@ -1,6 +1,6 @@
from os import environ from os import environ
PORT = 8080 PORT = 80
DB_URL = ( DB_URL = (
environ.get("DATABASE_URL") or environ.get("DB_URL") or environ.get("DATABASE_URL") or environ.get("DB_URL") or