fix: job_queue 모듈 import 방식 수정 — None 참조 해결
모듈 레벨 변수를 직접 import하면 init_queue() 이후에도 None 참조가 유지됨. 모듈 자체를 import하여 접근. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -13,7 +13,7 @@ from config import settings
|
||||
from db.database import init_db
|
||||
from routers import chat
|
||||
from services.backend_registry import backend_registry
|
||||
from services.job_queue import init_queue, job_queue
|
||||
from services import job_queue as jq_module
|
||||
|
||||
logging.basicConfig(
|
||||
level=logging.INFO,
|
||||
@@ -26,7 +26,7 @@ async def lifespan(app: FastAPI):
|
||||
await init_db()
|
||||
backend_registry.init_from_settings(settings)
|
||||
backend_registry.start_health_loop(settings.health_check_interval)
|
||||
init_queue(settings.max_concurrent_jobs)
|
||||
jq_module.init_queue(settings.max_concurrent_jobs)
|
||||
yield
|
||||
backend_registry.stop_health_loop()
|
||||
|
||||
@@ -66,9 +66,8 @@ async def root():
|
||||
|
||||
@app.get("/health")
|
||||
async def health():
|
||||
from services.job_queue import job_queue
|
||||
return {
|
||||
"status": "ok",
|
||||
"backends": backend_registry.health_summary(),
|
||||
"queue": job_queue.stats if job_queue else {},
|
||||
"queue": jq_module.job_queue.stats if jq_module.job_queue else {},
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ from fastapi.responses import StreamingResponse
|
||||
|
||||
from models.schemas import CancelResponse, ChatRequest, ChatResponse, JobStatusResponse
|
||||
from services.job_manager import job_manager
|
||||
from services.job_queue import job_queue
|
||||
from services import job_queue as jq_module
|
||||
from services.state_stream import state_stream
|
||||
|
||||
router = APIRouter(tags=["chat"])
|
||||
@@ -18,7 +18,7 @@ async def create_chat(body: ChatRequest):
|
||||
"""job_id 즉시 반환 (ACK). 백그라운드에서 파이프라인 처리 시작."""
|
||||
job = job_manager.create(body.message)
|
||||
state_stream.create(job.id)
|
||||
await job_queue.submit(job)
|
||||
await jq_module.job_queue.submit(job)
|
||||
return ChatResponse(job_id=job.id)
|
||||
|
||||
|
||||
@@ -59,7 +59,7 @@ async def job_status(job_id: str):
|
||||
status=job.status,
|
||||
created_at=job.created_at,
|
||||
pipeline=job.pipeline,
|
||||
queue_position=job_queue.position(job.id) if job_queue else None,
|
||||
queue_position=jq_module.job_queue.position(job.id) if jq_module.job_queue else None,
|
||||
)
|
||||
|
||||
|
||||
@@ -75,6 +75,6 @@ async def cancel_chat(job_id: str):
|
||||
@router.get("/queue/stats")
|
||||
async def queue_stats():
|
||||
"""큐 통계."""
|
||||
if job_queue:
|
||||
return job_queue.stats
|
||||
if jq_module.job_queue:
|
||||
return jq_module.job_queue.stats
|
||||
return {"pending": 0, "active": 0}
|
||||
|
||||
Reference in New Issue
Block a user