API trước đây chỉ nhận đường dẫn HDFS từ Airflow. Thêm endpoint
multipart/form-data nhận thẳng file PDF, vẫn chạy bất đồng bộ: trả 202 kèm
job_id và result_url, worker xử lý nền, client lấy dla-document-bundle ở
GET /jobs/{job_id}/result hoặc qua callback.
- File upload ghi xuống IDP_DATA_DIR/uploads theo sha256 nội dung nên gửi lại
cùng request_id trả cùng job_id; file được xoá khi không còn job nào dùng.
- Thêm cột filename/source_kind để bundle giữ đúng tên file gốc thay vì tên
đã băm.
- IDP_RUN_WORKER=1 chạy worker trong process API cho triển khai một host.
- IDP_OCR_BACKEND=pdf_text dựng bundle từ text layer của PDF để chạy thử toàn
bộ luồng khi chưa serve được model.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2.0 KiB
2.0 KiB
Cấu trúc Airflow → IDP
0. Request: upload thẳng file PDF
POST /parse
Content-Type: multipart/form-data
file=@input.pdf
request_id=550e8400-e29b-41d4-a716-446655440000 # optional
callback_url=http://airflow-webserver:8080/... # optional
batch_id=... # optional
Trả 202 như mục 2, thêm result_url để lấy JSON. Dùng khi phía gọi có sẵn
file chứ không đẩy qua HDFS.
1. Request: Airflow → IDP
POST /process
Content-Type: application/json
{
"request_id": "550e8400-e29b-41d4-a716-446655440000",
"file_path": "/data/bronze/incoming/qudtw216_signed_7829c.pdf",
"file_type": "application/pdf",
"callback_url": "http://airflow-webserver:8080/api/v1/dags/bronze_ingest_trigger/dagRuns/{run_id}/taskInstances/trigger_idp/callback"
}
Giải thích field:
| Field | Bắt buộc | Ý nghĩa |
|---|---|---|
request_id |
✓ | UUID để trace/idempotency |
file_path |
✓ | Path tuyệt đối trên HDFS |
file_type |
optional | mime pdf/audio/json... |
callback_url |
optional | Callback response |
2. Response
Bước 1 — Nhận request:
HTTP 202 Accepted
{
"request_id": "550e8400-e29b-41d4-a716-446655440000",
"status": "accepted",
"job_id": "job-98765"
}
Bước 2 — IDP gọi callback_url khi xong:
POST {callback_url}
Content-Type: application/json
{
"request_id": "550e8400-e29b-41d4-a716-446655440000",
"job_id": "job-98765",
"status": "done",
"output": { ... },
}
output là dla-document-bundle, cùng schema với GET /jobs/{job_id}/result.
4. Mã lỗi
code |
description |
|---|---|
FILE_NOT_FOUND |
file_path không tồn tại trên HDFS |
FILE_READ_ERROR |
Lỗi network/permission khi đọc |
FILE_STILL_WRITING |
File chưa ghi xong |
PARSE_ERROR |
File đọc được nhưng lỗi khi xử lý nội dung |
TIMEOUT |
Xử lý quá thời gian cho phép |