fix: resolve sync and db query errors in Coordinator API jobs and db layers
This commit is contained in:
@@ -41,14 +41,14 @@ class JobService:
|
|||||||
query = select(Job).where(Job.id == job_id)
|
query = select(Job).where(Job.id == job_id)
|
||||||
if client_id:
|
if client_id:
|
||||||
query = query.where(Job.client_id == client_id)
|
query = query.where(Job.client_id == client_id)
|
||||||
job = self.session.exec(query).one_or_none()
|
job = self.session.execute(query).scalar_one_or_none()
|
||||||
if not job:
|
if not job:
|
||||||
raise KeyError("job not found")
|
raise KeyError("job not found")
|
||||||
return self._ensure_not_expired(job)
|
return self._ensure_not_expired(job)
|
||||||
|
|
||||||
def list_receipts(self, job_id: str, client_id: Optional[str] = None) -> list[JobReceipt]:
|
def list_receipts(self, job_id: str, client_id: Optional[str] = None) -> list[JobReceipt]:
|
||||||
job = self.get_job(job_id, client_id=client_id)
|
job = self.get_job(job_id, client_id=client_id)
|
||||||
receipts = self.session.exec(
|
receipts = self.session.scalars(
|
||||||
select(JobReceipt)
|
select(JobReceipt)
|
||||||
.where(JobReceipt.job_id == job.id)
|
.where(JobReceipt.job_id == job.id)
|
||||||
.order_by(JobReceipt.created_at.asc())
|
.order_by(JobReceipt.created_at.asc())
|
||||||
@@ -94,7 +94,7 @@ class JobService:
|
|||||||
.order_by(Job.requested_at.asc())
|
.order_by(Job.requested_at.asc())
|
||||||
)
|
)
|
||||||
|
|
||||||
jobs = self.session.exec(statement).all()
|
jobs = self.session.scalars(statement).all()
|
||||||
for job in jobs:
|
for job in jobs:
|
||||||
try:
|
try:
|
||||||
job = self._ensure_not_expired(job)
|
job = self._ensure_not_expired(job)
|
||||||
|
|||||||
@@ -58,6 +58,8 @@ def get_engine() -> Engine:
|
|||||||
return _engine
|
return _engine
|
||||||
|
|
||||||
|
|
||||||
|
from app.domain import *
|
||||||
|
|
||||||
def init_db() -> Engine:
|
def init_db() -> Engine:
|
||||||
"""Initialize database tables and ensure data directory exists."""
|
"""Initialize database tables and ensure data directory exists."""
|
||||||
engine = get_engine()
|
engine = get_engine()
|
||||||
@@ -89,10 +91,11 @@ def session_scope() -> Generator[Session, None, None]:
|
|||||||
from fastapi import Depends
|
from fastapi import Depends
|
||||||
from typing import Annotated
|
from typing import Annotated
|
||||||
|
|
||||||
def get_session() -> Session:
|
def get_session():
|
||||||
"""Get a database session."""
|
"""Get a database session."""
|
||||||
engine = get_engine()
|
engine = get_engine()
|
||||||
return Session(engine)
|
with Session(engine) as session:
|
||||||
|
yield session
|
||||||
|
|
||||||
SessionDep = Annotated[Session, Depends(get_session)]
|
SessionDep = Annotated[Session, Depends(get_session)]
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user