Auto-resume: cleanup stuck jobs on container startup + GEMINI_API_KEY env
- @app.on_event(startup) marks all status=processing jobs as error after restart - Process endpoint now clears chorus_error/interrupted_at on retry (retry-friendly) - GEMINI_API_KEY added to Coolify env (Gemini 3.1 Pro now active) - User can now choose Gemini in UI dropdown for analysis
This commit is contained in:
parent
ec71c54570
commit
32baf9cd45
31
app/main.py
31
app/main.py
@ -373,6 +373,34 @@ app = FastAPI(title="Reels Clipper")
|
||||
app.mount("/static", StaticFiles(directory=Path(__file__).parent.parent / "static"), name="static")
|
||||
|
||||
|
||||
@app.on_event("startup")
|
||||
async def cleanup_stuck_jobs():
|
||||
"""Ob startu containerja: označi vse 'processing' jobs kot prekinjene.
|
||||
|
||||
Ko Coolify deployа nov container, prejšnji se ubije sredi obdelave,
|
||||
JSON file pa ostane status='processing'. Tukaj preverimo in počistimo.
|
||||
"""
|
||||
print("🔄 Preverjam stuck jobs...")
|
||||
cleaned = 0
|
||||
for f in JOBS_DIR.glob("*.json"):
|
||||
try:
|
||||
j = json.loads(f.read_text())
|
||||
if j.get("status") == "processing":
|
||||
j["status"] = "error"
|
||||
j["current_step"] = "Prekinjeno (container restart) — naloži ponovno"
|
||||
j["chorus_error"] = "Container restart during deploy. Napaka ni vaša — obnovite z gumbom Process."
|
||||
j["interrupted_at"] = time.time()
|
||||
j["updated_at"] = time.time()
|
||||
f.write_text(json.dumps(j, ensure_ascii=False, indent=2))
|
||||
cleaned += 1
|
||||
except Exception as e:
|
||||
print(f" ⚠️ Napaka pri {f.name}: {e}")
|
||||
if cleaned > 0:
|
||||
print(f" ✅ Označenih {cleaned} prekinjenih jobs")
|
||||
else:
|
||||
print(" 👍 Ni stuck jobs")
|
||||
|
||||
|
||||
@app.get("/", response_class=HTMLResponse)
|
||||
async def index(user: str = Depends(check_auth)):
|
||||
html = (Path(__file__).parent.parent / "templates" / "index.html").read_text()
|
||||
@ -523,6 +551,9 @@ async def start_processing(
|
||||
llm_provider=payload.llm_provider,
|
||||
llm_model=payload.llm_model,
|
||||
current_step="V vrsti za obdelavo",
|
||||
# Počisti pretekle napake (retry-friendly)
|
||||
chorus_error=None,
|
||||
interrupted_at=None,
|
||||
)
|
||||
background.add_task(process_job, payload.job_id)
|
||||
return load_job(payload.job_id)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user