phase8: report generation isolated in worker (ARQ background job) + async endpoint + DMS output
Check Cross-Plugin Imports / check (push) Has been cancelled
Check Cross-Plugin Imports / check (push) Has been cancelled
This commit is contained in:
@@ -410,6 +410,50 @@ async def generate_report(
|
||||
)
|
||||
|
||||
|
||||
@router.post("/generate/async")
|
||||
async def generate_report_async(
|
||||
body: ReportGenerateRequest,
|
||||
current_user: dict = Depends(require_permission("reports:generate")),
|
||||
):
|
||||
"""Submit a report generation job to the background worker.
|
||||
|
||||
Returns a job ID. The report is generated in the isolated worker process
|
||||
and stored in DMS. Poll /api/v1/reports/{job_id} for status.
|
||||
"""
|
||||
from arq import create_pool
|
||||
from arq.connections import RedisSettings
|
||||
from app.config import get_settings
|
||||
|
||||
settings = get_settings()
|
||||
tenant_id = current_user["tenant_id"]
|
||||
user_id = current_user["user_id"]
|
||||
|
||||
redis = await create_pool(RedisSettings(
|
||||
host=settings.redis_host,
|
||||
port=settings.redis_port,
|
||||
password=settings.redis_password or None,
|
||||
))
|
||||
|
||||
job = await redis.enqueue_job(
|
||||
"generate_report",
|
||||
tenant_id=tenant_id,
|
||||
user_id=user_id,
|
||||
template_id=body.template_id,
|
||||
data=body.data,
|
||||
output_format=body.output_format,
|
||||
)
|
||||
|
||||
await redis.close()
|
||||
|
||||
if job is None:
|
||||
raise HTTPException(
|
||||
503,
|
||||
detail={"detail": "Failed to enqueue report job", "code": "enqueue_failed"},
|
||||
)
|
||||
|
||||
return {"job_id": job.job_id, "status": "queued"}
|
||||
|
||||
|
||||
@router.get("/{report_id}")
|
||||
async def get_report(
|
||||
report_id: str,
|
||||
|
||||
Reference in New Issue
Block a user