From 6cb94ef447219e66ca78a6075b2668d7ae6e2499 Mon Sep 17 00:00:00 2001
From: Ari Archer
Date: Sun, 10 Nov 2024 20:01:03 +0200
Subject: [PATCH] Improve multiprocessing capabilities.
Signed-off-by: Ari Archer
---
run.sh | 2 +-
src/aw/views.py | 22 +++++++++++++---------
src/templates/index.j2 | 2 +-
3 files changed, 15 insertions(+), 11 deletions(-)
diff --git a/run.sh b/run.sh
index eda1996..1a789b5 100755
--- a/run.sh
+++ b/run.sh
@@ -7,7 +7,7 @@ main() {
kill -9 $(pgrep gunicorn) || true
kill -9 $(pgrep memcached) || true
- memcached -d -p 41923
+ memcached -d -p 41923 -m 1024
source ari-lt.env
cd src
python3 -m pip install gunicorn
diff --git a/src/aw/views.py b/src/aw/views.py
index b630ba6..b544cbf 100644
--- a/src/aw/views.py
+++ b/src/aw/views.py
@@ -6,6 +6,7 @@ import datetime
import hashlib
import os
import typing as t
+from multiprocessing import Manager
import flask
import validators
@@ -18,10 +19,13 @@ from .limiter import limiter
from .routing import Bp
views: Bp = Bp("views", __name__)
-status: t.Dict[str, t.Any] = {
- "status": "No status",
- "last_updated": datetime.datetime.now(datetime.timezone.utc),
-}
+manager = Manager()
+status = manager.dict(
+ {
+ "status": "No status",
+ "last_updated": datetime.datetime.now(datetime.timezone.utc),
+ }
+)
@views.get("/status")
@@ -29,8 +33,8 @@ def get_status() -> t.Any:
"""Get status"""
return flask.jsonify( # type: ignore
{
- "status": status["status"],
- "last_updated": status["last_updated"].timestamp(),
+ "status": status["status"], # type: ignore
+ "last_updated": status["last_updated"].timestamp(), # type: ignore
}
)
@@ -60,11 +64,11 @@ def set_status() -> Response:
and flask.request.headers.get("X-Admin-Key", None) == os.environ["ADMIN_KEY"]
):
status["status"] = str(flask.request.form["status"]) # type: ignore
- status["last_updated"] = datetime.datetime.now(datetime.timezone.utc)
+ status["last_updated"] = datetime.datetime.now(datetime.timezone.utc) # type: ignore
return flask.jsonify( # type: ignore
{
- "status": status["status"],
- "last_updated": status["last_updated"].timestamp(),
+ "status": status["status"], # type: ignore
+ "last_updated": status["last_updated"].timestamp(), # type: ignore
}
)
else:
diff --git a/src/templates/index.j2 b/src/templates/index.j2
index 7fd0aa2..3aef49b 100644
--- a/src/templates/index.j2
+++ b/src/templates/index.j2
@@ -175,7 +175,7 @@
this is a good introduction to what I do, what skills I posses.
-
+
*** Current status ***
{{ status["status"] }}