Skip to content

Commit 4909fc2

Browse files
committed
fix: update intelligence API key and improve ILP job progress
Keep API and intelligence service keys aligned during VPS enable-ilp, and advance async image job progress during long CPU-backed removeBg/upscale runs instead of stalling at 15%.
1 parent e1f1f74 commit 4909fc2

2 files changed

Lines changed: 39 additions & 11 deletions

File tree

‎apps/api/app/api/routes/image_process_jobs.py‎

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from __future__ import annotations
44

5+
import contextlib
56
import logging
67
import uuid
78
from typing import Any
@@ -41,6 +42,8 @@ class ImageProcessJobStatusResponse(BaseModel):
4142

4243
async def execute_image_process(job: dict[str, Any]) -> dict[str, Any]:
4344
"""Run toolbar image tool; credits must already be charged."""
45+
import asyncio
46+
4447
from app.services.llm.image_tools import process_image_tool
4548

4649
job_id = str(job.get("job_id") or "")
@@ -58,20 +61,35 @@ def _ilp_progress(pct: int, _stage: str = "") -> None:
5861
progress=max(15, min(85, 15 + int(pct * 0.7))),
5962
)
6063

64+
async def _heartbeat_progress() -> None:
65+
"""Slowly advance progress for long ILP jobs without granular callbacks."""
66+
pct = 15
67+
while pct < 84:
68+
await asyncio.sleep(3)
69+
pct = min(84, pct + 4)
70+
if job_id:
71+
update_job(job_id, kind=_KIND, progress=pct)
72+
6173
if job_id:
6274
update_job(job_id, kind=_KIND, progress=15)
6375

64-
result = await process_image_tool(
65-
kind=tool_kind,
66-
image=image,
67-
meta=job.get("meta") if isinstance(job.get("meta"), dict) else None,
68-
aspect_ratio=job.get("aspect_ratio"),
69-
quality=job.get("quality"),
70-
resolution=job.get("resolution"),
71-
model=job.get("model"),
72-
user_id=user_id,
73-
on_progress=_ilp_progress if tool_kind == "editElements" else None,
74-
)
76+
heartbeat = asyncio.create_task(_heartbeat_progress())
77+
try:
78+
result = await process_image_tool(
79+
kind=tool_kind,
80+
image=image,
81+
meta=job.get("meta") if isinstance(job.get("meta"), dict) else None,
82+
aspect_ratio=job.get("aspect_ratio"),
83+
quality=job.get("quality"),
84+
resolution=job.get("resolution"),
85+
model=job.get("model"),
86+
user_id=user_id,
87+
on_progress=_ilp_progress if tool_kind == "editElements" else None,
88+
)
89+
finally:
90+
heartbeat.cancel()
91+
with contextlib.suppress(asyncio.CancelledError):
92+
await heartbeat
7593

7694
if job_id:
7795
update_job(job_id, kind=_KIND, progress=90)

‎deploy/vps/enable-ilp.sh‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,16 @@ set_kv IMAGE_LAYER_PIPELINE_API_KEY "$KEY"
4040
set_kv IMAGE_LAYER_PIPELINE_MODE ilp
4141
set_kv IMAGE_LAYER_PIPELINE_TIMEOUT_SEC 300
4242

43+
INTEL_ENV="${RECOMBYN_INTELLIGENCE_CONTEXT:-/opt/recombyn-intelligence}/.env"
44+
if [ -f "$INTEL_ENV" ]; then
45+
if grep -q '^INTELLIGENCE_SERVICE_API_KEY=' "$INTEL_ENV"; then
46+
sed -i "s|^INTELLIGENCE_SERVICE_API_KEY=.*|INTELLIGENCE_SERVICE_API_KEY=${KEY}|" "$INTEL_ENV"
47+
else
48+
echo "INTELLIGENCE_SERVICE_API_KEY=${KEY}" >> "$INTEL_ENV"
49+
fi
50+
echo "[enable-ilp] synced INTELLIGENCE_SERVICE_API_KEY in ${INTEL_ENV}"
51+
fi
52+
4353
COMPOSE=(sudo docker compose -f docker-compose.yml -f docker-compose.prod.yml -f docker-compose.override.yml)
4454
"${COMPOSE[@]}" up -d api worker
4555

0 commit comments

Comments
 (0)