feat: add list_pending_jobs and get_pending_job
This commit is contained in:
@@ -124,3 +124,28 @@ def confirm_submit_job(*, pending_id: str) -> SubmitResult:
|
||||
application_id=application_id,
|
||||
tracking_url=tracking_url,
|
||||
)
|
||||
|
||||
|
||||
def list_pending_jobs() -> list[dict[str, object]]:
|
||||
return [p.model_dump() for p in pending_store.list_all()]
|
||||
|
||||
|
||||
def get_pending_job(pending_id: str) -> dict[str, object]:
|
||||
p = pending_store.get(pending_id)
|
||||
if p is None:
|
||||
raise KeyError(f"Unknown pending_id: {pending_id}")
|
||||
return p.model_dump()
|
||||
|
||||
|
||||
def cancel_pending_job(pending_id: str) -> dict[str, str]:
|
||||
p = pending_store.get(pending_id)
|
||||
if p is None:
|
||||
raise KeyError(f"Unknown pending_id: {pending_id}")
|
||||
if p.status in ("SUBMITTED", "FAILED"):
|
||||
raise ValueError(
|
||||
f"pending_id {pending_id} is in status {p.status!r} and cannot be cancelled"
|
||||
)
|
||||
p.status = "CANCELLED"
|
||||
pending_store.save(p)
|
||||
logger.info(f"cancel_pending_job pending_id={pending_id}")
|
||||
return {"pending_id": pending_id, "status": "CANCELLED"}
|
||||
|
||||
Reference in New Issue
Block a user