fix: make deploy() non-blocking (fire-and-forget thread)
This commit is contained in:
1 parent
6107873cfa
commit
5a144753b8
2 files changed
+14
-7
No files matched your search
Binary file not shown.
@@ -17,7 +17,7 @@ Endpoints (all behind Traefik basic-auth in prod):
|
|||||||
POST /rebuild rebuild catalog.json from /movies
|
POST /rebuild rebuild catalog.json from /movies
|
||||||
POST /deploy trigger Coolify webhook
|
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 pathlib import Path
|
||||||
from fastapi import FastAPI, HTTPException, UploadFile, File, Form
|
from fastapi import FastAPI, HTTPException, UploadFile, File, Form
|
||||||
from fastapi.responses import JSONResponse
|
from fastapi.responses import JSONResponse
|
||||||
@@ -48,18 +48,25 @@ def load_catalog():
|
|||||||
return {"movies": []}
|
return {"movies": []}
|
||||||
return json.loads(CATALOG.read_text(encoding="utf-8"))
|
return json.loads(CATALOG.read_text(encoding="utf-8"))
|
||||||
|
|
||||||
def deploy():
|
def _deploy_worker():
|
||||||
if not WEBHOOK:
|
if not WEBHOOK:
|
||||||
return {"deployed": False, "reason": "no webhook configured"}
|
return
|
||||||
import urllib.request
|
import urllib.request
|
||||||
req = urllib.request.Request(WEBHOOK, method="POST")
|
req = urllib.request.Request(WEBHOOK, method="POST")
|
||||||
if WEBHOOK_TOKEN:
|
if WEBHOOK_TOKEN:
|
||||||
req.add_header("Authorization", "Bearer " + WEBHOOK_TOKEN)
|
req.add_header("Authorization", "Bearer " + WEBHOOK_TOKEN)
|
||||||
try:
|
try:
|
||||||
with urllib.request.urlopen(req, timeout=60) as r:
|
urllib.request.urlopen(req, timeout=60)
|
||||||
return {"deployed": True, "status": r.status}
|
except Exception:
|
||||||
except Exception as e:
|
pass # fire-and-forget: log silently, don't block the request
|
||||||
return {"deployed": False, "error": str(e)}
|
|
||||||
|
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):
|
def torrent_hash(path: Path):
|
||||||
"""Extract info_dict sha1 from a .torrent (bencode) like build_catalog.sh."""
|
"""Extract info_dict sha1 from a .torrent (bencode) like build_catalog.sh."""
|
||||||
|
|||||||
Reference in new issue
Block a user