feat: show progress while preparing batch archives
This commit is contained in:
1 parent
868f611c36
commit
8dbe054a8c
8 files changed
+333
-7
No files matched your search
@@ -10,6 +10,7 @@ from pydantic import BaseModel, Field
|
||||
|
||||
from apps.admin_console.services.automation_store import identifier, store
|
||||
from apps.admin_console.services import automation_service as service
|
||||
from apps.admin_console.services import batch_archive as archive_service
|
||||
from apps.admin_console.services import report_export, task_import
|
||||
|
||||
router = APIRouter(prefix="/api/automation", tags=["automation"])
|
||||
@@ -128,10 +129,13 @@ def delete_batch(batch_id: str):
|
||||
except ValueError as exc:
|
||||
raise HTTPException(400, str(exc)) from exc
|
||||
try:
|
||||
if archive_service.status(key, require("batch", key))["status"] == "preparing":
|
||||
raise HTTPException(409, "报告正在打包,请完成后再删除批次")
|
||||
if not service.delete_batch(key):
|
||||
raise HTTPException(404, "批次不存在")
|
||||
except ValueError as exc:
|
||||
raise HTTPException(409, str(exc)) from exc
|
||||
archive_service.forget(key)
|
||||
return {"batch_id": key, "status": "deleted"}
|
||||
|
||||
|
||||
@@ -144,10 +148,30 @@ def batch_action(batch_id: str, action: Literal["pause", "resume", "retry_failed
|
||||
raise HTTPException(409, str(exc)) from exc
|
||||
|
||||
|
||||
@router.post("/batches/{batch_id}/archive/prepare")
|
||||
def prepare_batch_archive(batch_id: str):
|
||||
batch = require("batch", batch_id)
|
||||
return archive_service.prepare(batch_id, batch)
|
||||
|
||||
|
||||
@router.get("/batches/{batch_id}/archive/status")
|
||||
def batch_archive_status(batch_id: str):
|
||||
batch = require("batch", batch_id)
|
||||
return archive_service.status(batch_id, batch)
|
||||
|
||||
|
||||
@router.get("/batches/{batch_id}/archive")
|
||||
async def batch_archive(batch_id: str):
|
||||
require("batch", batch_id)
|
||||
path = await asyncio.to_thread(report_export.export_batch, batch_id)
|
||||
batch = require("batch", batch_id)
|
||||
if archive_service.status(batch_id, batch)["status"] == "preparing":
|
||||
raise HTTPException(409, "报告正在打包,请等待准备完成")
|
||||
path = archive_service.archive_path(batch_id)
|
||||
if (
|
||||
not path.is_file()
|
||||
or not batch.get("report_ready")
|
||||
and archive_service.status(batch_id, batch)["status"] != "ready"
|
||||
):
|
||||
path = await asyncio.to_thread(report_export.export_batch, batch_id)
|
||||
return FileResponse(path, filename=f"批次报告-{batch_id[:8]}.zip")
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user