(task_id: str)
| 87 | return TaskResults( |
| 88 | task_id=task_id, |
| 89 | results=[TaskResult(name=output.name, type=output.type, media_type=output.media_type, url=f"/v1/tasks/{task_id}/results/{output.name}") for output in task.results], |
| 90 | ) |
| 91 | |
| 92 | |
| 93 | @router.get("/{task_id}/results/{name}") |
| 94 | async def download_task_result(task_id: str, name: str): |
| 95 | task = _completed_task(task_id) |
| 96 | output = next((output for output in task.results if output.name == name), None) |
| 97 | if output is None: |
| 98 | raise HTTPException(status_code=404, detail="Result not found") |
| 99 | content = output.content |
| 100 | if content is not None: |
| 101 | return Response(content=content, media_type="image/png" if output.type == "image" else output.media_type) |
| 102 | if output.path is None: |
| 103 | raise HTTPException(status_code=410, detail="Result is no longer in memory; submit a new task to regenerate it") |
| 104 | path = Path(output.path) |
| 105 | if not path.is_file(): |
| 106 | raise HTTPException(status_code=404, detail="Result file not found") |
| 107 | return FileResponse(path, media_type=output.media_type, filename=path.name) |
| 108 | |
| 109 | |
| 110 | @router.delete("/{task_id}", response_model=StopTaskResponse) |
| 111 | async def stop_task(task_id: str): |
| 112 | try: |
| 113 | if task_manager.cancel_task(task_id): |
| 114 | gc.collect() |
| 115 | if torch.cuda.is_available(): |
| 116 | torch.cuda.empty_cache() |
| 117 | logger.info(f"Task {task_id} stopped successfully.") |
| 118 | return StopTaskResponse(stop_status="success", reason="Task stopped successfully.") |
| 119 | else: |
| 120 | return StopTaskResponse(stop_status="do_nothing", reason="Task not found or already completed.") |
nothing calls this directly
no test coverage detected