diff --git a/__pycache__/app.cpython-310.pyc b/__pycache__/app.cpython-310.pyc index 201b183..1188807 100644 Binary files a/__pycache__/app.cpython-310.pyc and b/__pycache__/app.cpython-310.pyc differ diff --git a/app.py b/app.py index 31c87ef..c42846f 100644 --- a/app.py +++ b/app.py @@ -17,7 +17,7 @@ Endpoints (all behind Traefik basic-auth in prod): POST /rebuild rebuild catalog.json from /movies POST /deploy trigger Coolify webhook """ -import os, re, json, shutil, subprocess, hashlib, datetime, unicodedata +import os, re, json, shutil, subprocess, hashlib, datetime, unicodedata, threading from pathlib import Path from fastapi import FastAPI, HTTPException, UploadFile, File, Form from fastapi.responses import JSONResponse @@ -48,18 +48,25 @@ def load_catalog(): return {"movies": []} return json.loads(CATALOG.read_text(encoding="utf-8")) -def deploy(): +def _deploy_worker(): if not WEBHOOK: - return {"deployed": False, "reason": "no webhook configured"} + return import urllib.request req = urllib.request.Request(WEBHOOK, method="POST") if WEBHOOK_TOKEN: req.add_header("Authorization", "Bearer " + WEBHOOK_TOKEN) try: - with urllib.request.urlopen(req, timeout=60) as r: - return {"deployed": True, "status": r.status} - except Exception as e: - return {"deployed": False, "error": str(e)} + urllib.request.urlopen(req, timeout=60) + except Exception: + pass # fire-and-forget: log silently, don't block the request + +def deploy(): + """Trigger Coolify redeploy asynchronously (non-blocking).""" + if not WEBHOOK: + return {"deployed": False, "reason": "no webhook configured"} + t = threading.Thread(target=_deploy_worker, daemon=True) + t.start() + return {"deployed": "queued"} def torrent_hash(path: Path): """Extract info_dict sha1 from a .torrent (bencode) like build_catalog.sh."""