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
@@ -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."""
|
||||
|
||||
Reference in new issue
Block a user