mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-06-08 11:17:27 +00:00
get the most recent task for a given service, source, and source ID
This commit is contained in:
parent
3bae341f69
commit
d33ec39aea
1 changed files with 24 additions and 1 deletions
|
|
@ -16,7 +16,7 @@ from backend.app.tasks.schema import (
|
|||
from backend.app.db.functions.tasks.Tasks import TasksInterface, SubTaskInterface
|
||||
|
||||
from backend.app.db.connection import get_db_session
|
||||
from backend.app.db.models.tasks import Task, SubTask
|
||||
from backend.app.db.models.tasks import SourceEnum, Task, SubTask
|
||||
from sqlmodel import select
|
||||
|
||||
|
||||
|
|
@ -70,6 +70,29 @@ async def get_task(task_id: UUID):
|
|||
}
|
||||
|
||||
|
||||
@router.get(
|
||||
"/by-source/{source}/{source_id}/{service}",
|
||||
summary="Get the most recent task by source, source_id, and service",
|
||||
)
|
||||
async def get_task_by_source(source: SourceEnum, source_id: str, service: str):
|
||||
with get_db_session() as session:
|
||||
task = session.exec(
|
||||
select(Task)
|
||||
.where(
|
||||
Task.source == source,
|
||||
Task.source_id == source_id,
|
||||
Task.service == service,
|
||||
)
|
||||
.order_by(Task.job_started.desc())
|
||||
.limit(1)
|
||||
).first()
|
||||
|
||||
if not task:
|
||||
raise HTTPException(status_code=404, detail="Task not found")
|
||||
|
||||
return {"task": task}
|
||||
|
||||
|
||||
# ============================================================
|
||||
# Update Task Status
|
||||
# ============================================================
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue