Somewhat working routes for stats and logging
authorJacob <jobs@jacobcasper.com>
Sun, 7 Sep 2025 17:17:36 +0000 (12:17 -0500)
committerJacob <jobs@jacobcasper.com>
Sun, 7 Sep 2025 17:17:36 +0000 (12:17 -0500)
Dockerfile
compose.yaml
main.py
pyproject.toml
uv.lock

index cddba96205587812255cc7cdd34d40920912fe56..aae3b2243fb77509d7e95952751b1c1ceb5365e2 100644 (file)
@@ -4,4 +4,4 @@ COPY pyproject.toml pyproject.toml
 RUN pip install .
 EXPOSE 5000
 COPY . .
-ENTRYPOINT ["flask", "--app", "main", "run", "--host=0.0.0.0"]
+ENTRYPOINT ["flask", "--app", "main", "run", "--host=0.0.0.0", "--debug"]
index 1a707df672cabd7713368da001936ef88377d369..fb935fef905ead68bafffee3726a0b19bfb32665 100644 (file)
@@ -2,6 +2,6 @@ services:
   api:
     build: .
     ports:
-      - "8000:5000"
+      - "5000:5000"
   redis:
     image: "redis"
diff --git a/main.py b/main.py
index c1eb8e7fb0755547eec29a06cf170918baf0fd65..1928927a50ae460c5f3cd765da3651122748f92d 100644 (file)
--- a/main.py
+++ b/main.py
@@ -1,14 +1,33 @@
-from flask import Flask
+from flask import Flask, Response, request
 from redis import Redis
+import logging
 
-r = Redis(host="localhost", port=6379, decode_responses=True)
+r = Redis(host="redis", port=6379, decode_responses=True)
 
+logging.basicConfig(level=logging.DEBUG)
 app = Flask(__name__)
 
+
 @app.route("/stats", methods=["GET"])
 def stats():
-    return r.get("stats")
-           
+    try:
+        stats = r.get("stats")
+        if stats is None:
+            app.logger.debug("Uninitialized stats object")
+            return {}
+        return r.get("stats")
+    except redis.exceptions.ConnectionError as e:
+        app.logger.exception(e)
+        return Response("Internal Server Error", 500)
+    except Exception as e:
+        app.logger.exception(e)
+    return {}
+
+
+@app.route("/api/", methods=["GET"])
+def api():
+    return {"req": request.values}
+
 
 def main():
     app.run()
index 699a491dc7a69fd5518a4e2e95775ad5393812fe..a856dc3da8163e1c7f4b24706096cad7bbce58cb 100644 (file)
@@ -8,3 +8,8 @@ dependencies = [
     "flask>=3.1.2",
     "redis>=6.4.0",
 ]
+
+[dependency-groups]
+dev = [
+    "black>=25.1.0",
+]
diff --git a/uv.lock b/uv.lock
index 5e7833b325c8cb1ed12aa1a7944df77982997292..3bee78cb91ccd180ec1e1d0add2e0b05d8b90f50 100644 (file)
--- a/uv.lock
+++ b/uv.lock
@@ -2,6 +2,26 @@ version = 1
 revision = 3
 requires-python = ">=3.13"
 
+[[package]]
+name = "black"
+version = "25.1.0"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+    { name = "click" },
+    { name = "mypy-extensions" },
+    { name = "packaging" },
+    { name = "pathspec" },
+    { name = "platformdirs" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/94/49/26a7b0f3f35da4b5a65f081943b7bcd22d7002f5f0fb8098ec1ff21cb6ef/black-25.1.0.tar.gz", hash = "sha256:33496d5cd1222ad73391352b4ae8da15253c5de89b93a80b3e2c8d9a19ec2666", size = 649449, upload-time = "2025-01-29T04:15:40.373Z" }
+wheels = [
+    { url = "https://files.pythonhosted.org/packages/98/87/0edf98916640efa5d0696e1abb0a8357b52e69e82322628f25bf14d263d1/black-25.1.0-cp313-cp313-macosx_10_13_x86_64.whl", hash = "sha256:8f0b18a02996a836cc9c9c78e5babec10930862827b1b724ddfe98ccf2f2fe4f", size = 1650673, upload-time = "2025-01-29T05:37:20.574Z" },
+    { url = "https://files.pythonhosted.org/packages/52/e5/f7bf17207cf87fa6e9b676576749c6b6ed0d70f179a3d812c997870291c3/black-25.1.0-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:afebb7098bfbc70037a053b91ae8437c3857482d3a690fefc03e9ff7aa9a5fd3", size = 1453190, upload-time = "2025-01-29T05:37:22.106Z" },
+    { url = "https://files.pythonhosted.org/packages/e3/ee/adda3d46d4a9120772fae6de454c8495603c37c4c3b9c60f25b1ab6401fe/black-25.1.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:030b9759066a4ee5e5aca28c3c77f9c64789cdd4de8ac1df642c40b708be6171", size = 1782926, upload-time = "2025-01-29T04:18:58.564Z" },
+    { url = "https://files.pythonhosted.org/packages/cc/64/94eb5f45dcb997d2082f097a3944cfc7fe87e071907f677e80788a2d7b7a/black-25.1.0-cp313-cp313-win_amd64.whl", hash = "sha256:a22f402b410566e2d1c950708c77ebf5ebd5d0d88a6a2e87c86d9fb48afa0d18", size = 1442613, upload-time = "2025-01-29T04:19:27.63Z" },
+    { url = "https://files.pythonhosted.org/packages/09/71/54e999902aed72baf26bca0d50781b01838251a462612966e9fc4891eadd/black-25.1.0-py3-none-any.whl", hash = "sha256:95e8176dae143ba9097f351d174fdaf0ccd29efb414b362ae3fd72bf0f710717", size = 207646, upload-time = "2025-01-29T04:15:38.082Z" },
+]
+
 [[package]]
 name = "blinker"
 version = "1.9.0"
@@ -32,12 +52,20 @@ dependencies = [
     { name = "redis" },
 ]
 
+[package.dev-dependencies]
+dev = [
+    { name = "black" },
+]
+
 [package.metadata]
 requires-dist = [
     { name = "flask", specifier = ">=3.1.2" },
     { name = "redis", specifier = ">=6.4.0" },
 ]
 
+[package.metadata.requires-dev]
+dev = [{ name = "black", specifier = ">=25.1.0" }]
+
 [[package]]
 name = "colorama"
 version = "0.4.6"
@@ -113,6 +141,42 @@ wheels = [
     { url = "https://files.pythonhosted.org/packages/4f/65/6079a46068dfceaeabb5dcad6d674f5f5c61a6fa5673746f42a9f4c233b3/MarkupSafe-3.0.2-cp313-cp313t-win_amd64.whl", hash = "sha256:e444a31f8db13eb18ada366ab3cf45fd4b31e4db1236a4448f68778c1d1a5a2f", size = 15739, upload-time = "2024-10-18T15:21:42.784Z" },
 ]
 
+[[package]]
+name = "mypy-extensions"
+version = "1.1.0"
+source = { registry = "https://pypi.org/simple" }
+sdist = { url = "https://files.pythonhosted.org/packages/a2/6e/371856a3fb9d31ca8dac321cda606860fa4548858c0cc45d9d1d4ca2628b/mypy_extensions-1.1.0.tar.gz", hash = "sha256:52e68efc3284861e772bbcd66823fde5ae21fd2fdb51c62a211403730b916558", size = 6343, upload-time = "2025-04-22T14:54:24.164Z" }
+wheels = [
+    { url = "https://files.pythonhosted.org/packages/79/7b/2c79738432f5c924bef5071f933bcc9efd0473bac3b4aa584a6f7c1c8df8/mypy_extensions-1.1.0-py3-none-any.whl", hash = "sha256:1be4cccdb0f2482337c4743e60421de3a356cd97508abadd57d47403e94f5505", size = 4963, upload-time = "2025-04-22T14:54:22.983Z" },
+]
+
+[[package]]
+name = "packaging"
+version = "25.0"
+source = { registry = "https://pypi.org/simple" }
+sdist = { url = "https://files.pythonhosted.org/packages/a1/d4/1fc4078c65507b51b96ca8f8c3ba19e6a61c8253c72794544580a7b6c24d/packaging-25.0.tar.gz", hash = "sha256:d443872c98d677bf60f6a1f2f8c1cb748e8fe762d2bf9d3148b5599295b0fc4f", size = 165727, upload-time = "2025-04-19T11:48:59.673Z" }
+wheels = [
+    { url = "https://files.pythonhosted.org/packages/20/12/38679034af332785aac8774540895e234f4d07f7545804097de4b666afd8/packaging-25.0-py3-none-any.whl", hash = "sha256:29572ef2b1f17581046b3a2227d5c611fb25ec70ca1ba8554b24b0e69331a484", size = 66469, upload-time = "2025-04-19T11:48:57.875Z" },
+]
+
+[[package]]
+name = "pathspec"
+version = "0.12.1"
+source = { registry = "https://pypi.org/simple" }
+sdist = { url = "https://files.pythonhosted.org/packages/ca/bc/f35b8446f4531a7cb215605d100cd88b7ac6f44ab3fc94870c120ab3adbf/pathspec-0.12.1.tar.gz", hash = "sha256:a482d51503a1ab33b1c67a6c3813a26953dbdc71c31dacaef9a838c4e29f5712", size = 51043, upload-time = "2023-12-10T22:30:45Z" }
+wheels = [
+    { url = "https://files.pythonhosted.org/packages/cc/20/ff623b09d963f88bfde16306a54e12ee5ea43e9b597108672ff3a408aad6/pathspec-0.12.1-py3-none-any.whl", hash = "sha256:a0d503e138a4c123b27490a4f7beda6a01c6f288df0e4a8b79c7eb0dc7b4cc08", size = 31191, upload-time = "2023-12-10T22:30:43.14Z" },
+]
+
+[[package]]
+name = "platformdirs"
+version = "4.4.0"
+source = { registry = "https://pypi.org/simple" }
+sdist = { url = "https://files.pythonhosted.org/packages/23/e8/21db9c9987b0e728855bd57bff6984f67952bea55d6f75e055c46b5383e8/platformdirs-4.4.0.tar.gz", hash = "sha256:ca753cf4d81dc309bc67b0ea38fd15dc97bc30ce419a7f58d13eb3bf14c4febf", size = 21634, upload-time = "2025-08-26T14:32:04.268Z" }
+wheels = [
+    { url = "https://files.pythonhosted.org/packages/40/4b/2028861e724d3bd36227adfa20d3fd24c3fc6d52032f4a93c133be5d17ce/platformdirs-4.4.0-py3-none-any.whl", hash = "sha256:abd01743f24e5287cd7a5db3752faf1a2d65353f38ec26d98e25a6db65958c85", size = 18654, upload-time = "2025-08-26T14:32:02.735Z" },
+]
+
 [[package]]
 name = "redis"
 version = "6.4.0"