qaechi-batch 0.2.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- qaechi_batch-0.2.0/LICENSE +202 -0
- qaechi_batch-0.2.0/PKG-INFO +303 -0
- qaechi_batch-0.2.0/README.md +258 -0
- qaechi_batch-0.2.0/pyproject.toml +83 -0
- qaechi_batch-0.2.0/qaechi/batch/__init__.py +8 -0
- qaechi_batch-0.2.0/qaechi/batch/api.py +140 -0
- qaechi_batch-0.2.0/qaechi/batch/cli.py +258 -0
- qaechi_batch-0.2.0/qaechi/batch/client.py +139 -0
- qaechi_batch-0.2.0/qaechi/batch/config.py +91 -0
- qaechi_batch-0.2.0/qaechi/batch/ingest.py +201 -0
- qaechi_batch-0.2.0/qaechi/batch/manifest.py +349 -0
- qaechi_batch-0.2.0/qaechi/batch/models.py +191 -0
- qaechi_batch-0.2.0/qaechi/batch/publisher.py +152 -0
- qaechi_batch-0.2.0/qaechi/batch/report.py +329 -0
- qaechi_batch-0.2.0/qaechi/batch/results.py +306 -0
- qaechi_batch-0.2.0/qaechi/batch/service.py +123 -0
- qaechi_batch-0.2.0/qaechi/batch/store.py +187 -0
- qaechi_batch-0.2.0/qaechi/batch/telemetry.py +173 -0
- qaechi_batch-0.2.0/qaechi/batch/validate.py +136 -0
- qaechi_batch-0.2.0/qaechi_batch.egg-info/PKG-INFO +303 -0
- qaechi_batch-0.2.0/qaechi_batch.egg-info/SOURCES.txt +32 -0
- qaechi_batch-0.2.0/qaechi_batch.egg-info/dependency_links.txt +1 -0
- qaechi_batch-0.2.0/qaechi_batch.egg-info/entry_points.txt +2 -0
- qaechi_batch-0.2.0/qaechi_batch.egg-info/requires.txt +27 -0
- qaechi_batch-0.2.0/qaechi_batch.egg-info/top_level.txt +1 -0
- qaechi_batch-0.2.0/setup.cfg +4 -0
- qaechi_batch-0.2.0/tests/test_api.py +196 -0
- qaechi_batch-0.2.0/tests/test_integration.py +136 -0
- qaechi_batch-0.2.0/tests/test_manifest.py +268 -0
- qaechi_batch-0.2.0/tests/test_package.py +28 -0
- qaechi_batch-0.2.0/tests/test_report.py +207 -0
- qaechi_batch-0.2.0/tests/test_results.py +237 -0
- qaechi_batch-0.2.0/tests/test_store.py +219 -0
- qaechi_batch-0.2.0/tests/test_telemetry.py +102 -0
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
202
|
+
|
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: qaechi-batch
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: Run qaechi document extraction over thousands of files: runs, progress, retries and reports.
|
|
5
|
+
Author: Taeyong Kang
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://github.com/qaechi/qaechi-batch
|
|
8
|
+
Project-URL: Documentation, https://qaechi.github.io/modules/
|
|
9
|
+
Project-URL: Issues, https://github.com/qaechi/qaechi-batch/issues
|
|
10
|
+
Project-URL: Changelog, https://github.com/qaechi/qaechi-batch/blob/main/CHANGELOG.md
|
|
11
|
+
Keywords: qaechi,batch,kafka,document-extraction,airflow
|
|
12
|
+
Classifier: Development Status :: 3 - Alpha
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Operating System :: OS Independent
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
19
|
+
Requires-Python: >=3.11
|
|
20
|
+
Description-Content-Type: text/markdown
|
|
21
|
+
License-File: LICENSE
|
|
22
|
+
Requires-Dist: pydantic<3,>=2.7
|
|
23
|
+
Requires-Dist: httpx<1,>=0.27
|
|
24
|
+
Requires-Dist: pyyaml<7,>=6.0.2
|
|
25
|
+
Requires-Dist: qaechi-contracts<2,>=1.1
|
|
26
|
+
Provides-Extra: server
|
|
27
|
+
Requires-Dist: fastapi<1,>=0.110; extra == "server"
|
|
28
|
+
Requires-Dist: uvicorn[standard]<1,>=0.29; extra == "server"
|
|
29
|
+
Requires-Dist: psycopg[binary,pool]<4,>=3.3.9; extra == "server"
|
|
30
|
+
Requires-Dist: confluent-kafka<3,>=2.16.2; extra == "server"
|
|
31
|
+
Provides-Extra: s3
|
|
32
|
+
Requires-Dist: boto3<2,>=1.35; extra == "s3"
|
|
33
|
+
Provides-Extra: otel
|
|
34
|
+
Requires-Dist: opentelemetry-api<2,>=1.45.2; extra == "otel"
|
|
35
|
+
Requires-Dist: opentelemetry-sdk<2,>=1.45.2; extra == "otel"
|
|
36
|
+
Requires-Dist: opentelemetry-exporter-otlp-proto-http<2,>=1.45.2; extra == "otel"
|
|
37
|
+
Provides-Extra: all
|
|
38
|
+
Requires-Dist: qaechi-batch[otel,s3,server]; extra == "all"
|
|
39
|
+
Provides-Extra: dev
|
|
40
|
+
Requires-Dist: qaechi-batch[all]; extra == "dev"
|
|
41
|
+
Requires-Dist: pytest<10,>=8; extra == "dev"
|
|
42
|
+
Requires-Dist: ruff==0.16.*; extra == "dev"
|
|
43
|
+
Requires-Dist: moto[s3]<6,>=5; extra == "dev"
|
|
44
|
+
Dynamic: license-file
|
|
45
|
+
|
|
46
|
+
# qaechi-batch
|
|
47
|
+
|
|
48
|
+
Run [qaechi](https://qaechi.github.io/) document extraction over thousands of files as one **run**:
|
|
49
|
+
a manifest in, one parser job per document out, with progress, retries, timeouts and a report at
|
|
50
|
+
the end. Built on the same Kafka topics as the parser's queue mode, so the workers you already run
|
|
51
|
+
do the work.
|
|
52
|
+
|
|
53
|
+
[한국어](README.ko.md) | [How the modules fit together](https://qaechi.github.io/modules/)
|
|
54
|
+
|
|
55
|
+
> **Status: 0.x.** The HTTP API, the run spec and the report format may still change before 1.0.
|
|
56
|
+
|
|
57
|
+
```text
|
|
58
|
+
manifest ──▶ qaechi-batch serve ──jobs──▶ qaechi.parse.jobs ──▶ qaechi-parser worker × N
|
|
59
|
+
(S3, file) │ ▲ │
|
|
60
|
+
│ └───────────── qaechi.parse.results ◀───────────┘
|
|
61
|
+
└──▶ PostgreSQL (runs, items) ──▶ report (JSON, CSV, HTML)
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## Install
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
pip install qaechi-batch # client and CLI: submit, status, wait
|
|
68
|
+
pip install "qaechi-batch[server]" # the coordinator: qaechi-batch serve
|
|
69
|
+
pip install "qaechi-batch[s3]" # manifests and reports in S3 or MinIO
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
The default install has no Kafka or database drivers, so callers such as Airflow workers stay light.
|
|
73
|
+
|
|
74
|
+
## Commands
|
|
75
|
+
|
|
76
|
+
| Command | |
|
|
77
|
+
|---|---|
|
|
78
|
+
| `qaechi-batch serve [--host] [--port]` | the coordinator: HTTP API (port 3200), publishing, result tracking, timeouts |
|
|
79
|
+
| `qaechi-batch validate <manifest>` | check a manifest without publishing (see below) |
|
|
80
|
+
| `qaechi-batch submit <manifest> [--spec] [--run-id] [--wait]` | start a run; with `--wait`, exit 1 unless it succeeded |
|
|
81
|
+
| `qaechi-batch status`, `wait`, `pause`, `resume`, `cancel`, `retry-failed` `<runId>` | follow and control a run |
|
|
82
|
+
| `qaechi-batch runs`, `items <runId> [--status failed]` | list runs, list a run's documents |
|
|
83
|
+
| `qaechi-batch report <runId> [--format json\|csv\|html] [-o file]` | the run's report: a summary, or a file (see [Reports](#reports)) |
|
|
84
|
+
|
|
85
|
+
The client commands talk to `QAECHI_BATCH_URL` (default `http://127.0.0.1:3200`) with
|
|
86
|
+
`QAECHI_INTERNAL_TOKEN`, and `--json` prints machine-readable output. The coordinator reads the
|
|
87
|
+
manifest, so give a path or `s3://` URI it can reach. Submitting again with the same `--run-id`
|
|
88
|
+
returns that run, so a scheduler can retry its task safely.
|
|
89
|
+
|
|
90
|
+
```console
|
|
91
|
+
$ qaechi-batch submit s3://docs/runs/2019.jsonl.gz --spec spec.yaml --run-id archive-2019 --wait
|
|
92
|
+
archive-2019: running, 1200/48210 done, 410/min, about 1.9 h left
|
|
93
|
+
...
|
|
94
|
+
archive-2019: succeeded, 48210/48210 done, 402/min
|
|
95
|
+
failed 37, succeeded 48173
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
From Python (default install):
|
|
99
|
+
|
|
100
|
+
```python
|
|
101
|
+
from qaechi.batch.client import BatchClient
|
|
102
|
+
|
|
103
|
+
with BatchClient() as batch:
|
|
104
|
+
run = batch.submit("s3://docs/runs/2019.jsonl.gz", {"defaults": {"docType": "contract"}},
|
|
105
|
+
run_id="archive-2019")
|
|
106
|
+
run = batch.wait(run.run_id)
|
|
107
|
+
if not batch.ok(run):
|
|
108
|
+
raise SystemExit(f"{run.run_id}: {run.status}")
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
### HTTP API
|
|
112
|
+
|
|
113
|
+
Every route but `/health` needs the header `X-Internal-Token`. Keep the API on an internal network.
|
|
114
|
+
|
|
115
|
+
| Method | Path | |
|
|
116
|
+
|---|---|---|
|
|
117
|
+
| POST | `/runs` | `{manifest, spec, runId?, name?}`: 202 and the run (`ingesting`), 200 if that runId exists, 409 if it exists with another manifest or spec |
|
|
118
|
+
| GET | `/runs`, `/runs/{runId}` | status, counts by item status, progress (rate per minute, estimated time left) |
|
|
119
|
+
| GET | `/runs/{runId}/items?status=failed&limit&offset` | documents in manifest order |
|
|
120
|
+
| GET | `/runs/{runId}/report?format=json\|csv\|html` | the report, built now (a running run gives the report so far) |
|
|
121
|
+
| POST | `/runs/{runId}/pause`, `/resume`, `/cancel`, `/retry-failed` | control; 409 if the run's state does not allow it |
|
|
122
|
+
| GET | `/health` | database and background loops; 503 when one is down |
|
|
123
|
+
|
|
124
|
+
## Manifests
|
|
125
|
+
|
|
126
|
+
A manifest lists the documents of a run. Rows are read as a stream, so millions of rows are fine.
|
|
127
|
+
|
|
128
|
+
```jsonl
|
|
129
|
+
{"documentId": "contract-2019-0001", "source": "archive/2019/0001.pdf", "docType": "contract"}
|
|
130
|
+
{"documentId": "inv-77", "source": "archive/inv/77.pdf", "docType": "invoice", "period": "2019-03", "etag": "9b2c..."}
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
| Form | |
|
|
134
|
+
|---|---|
|
|
135
|
+
| `.jsonl` (recommended) | one parser job request per line, camelCase |
|
|
136
|
+
| `.csv` | a header row with `documentId`, `source`, `docType`, `lines`, `period`, `sourceKind`, `requestedBy`, `etag`, `sha256`; `fields` come from the spec |
|
|
137
|
+
| `.jsonl.gz`, `.csv.gz` | gzip |
|
|
138
|
+
| `s3://bucket/prefix/`, `dir:/path` | a folder: every file is a row, `documentId` is its path, the spec's `rules` fill the rest |
|
|
139
|
+
|
|
140
|
+
Manifests can be local files or `s3://` (extra `s3`; MinIO or R2 with `QAECHI_S3_ENDPOINT_URL`).
|
|
141
|
+
`etag` or `sha256` is optional and lets incremental runs skip unchanged documents.
|
|
142
|
+
|
|
143
|
+
`source` is relative to the parser worker's source root, as in the job contract. Set
|
|
144
|
+
`QAECHI_BATCH_SOURCE_ROOT` to the same root (`s3://docs/archive` or `/data/docs`) and absolute
|
|
145
|
+
sources such as `s3://docs/archive/2019/1.pdf` are made relative to it; rows outside it are rejected.
|
|
146
|
+
|
|
147
|
+
A run spec holds what every document shares (YAML or JSON):
|
|
148
|
+
|
|
149
|
+
```yaml
|
|
150
|
+
name: archive-2019
|
|
151
|
+
defaults: # filled in where a row has nothing
|
|
152
|
+
docType: contract
|
|
153
|
+
fields: [{name: party_a}, {name: signed_on, kind: date}]
|
|
154
|
+
rules: # folders: the first matching glob wins
|
|
155
|
+
- match: "invoices/**/*.pdf"
|
|
156
|
+
docType: invoice
|
|
157
|
+
lines: true
|
|
158
|
+
- match: "**/*.tmp"
|
|
159
|
+
skip: true
|
|
160
|
+
retry: {maxAttempts: 3, onTimeout: true}
|
|
161
|
+
maxInFlight: 500
|
|
162
|
+
timeoutSeconds: 2100
|
|
163
|
+
failThreshold: 0.02
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
Check a manifest before running it:
|
|
167
|
+
|
|
168
|
+
```console
|
|
169
|
+
$ qaechi-batch validate s3://docs/runs/2019.jsonl.gz --spec spec.yaml
|
|
170
|
+
manifest s3://docs/runs/2019.jsonl.gz (jsonl)
|
|
171
|
+
rows 48210
|
|
172
|
+
docTypes contract 41877, invoice 6333
|
|
173
|
+
sources 20/20 sampled sources exist
|
|
174
|
+
OK
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
It reads every row, reports invalid rows with their line numbers and duplicate `documentId`s, and
|
|
178
|
+
checks that a sample of sources exists (`--sample`, default 20). Exit code 1 on any problem;
|
|
179
|
+
`--json` for scripts.
|
|
180
|
+
|
|
181
|
+
## Retries and control
|
|
182
|
+
|
|
183
|
+
| When | What happens |
|
|
184
|
+
|---|---|
|
|
185
|
+
| A job fails with a retryable `errorCode` (`timeout`, `rate_limited`, `upstream_error`, `internal`, or one not known yet) | Sent again with a new job ID after 30 s, 2 min, then 8 min, up to `retry.maxAttempts` |
|
|
186
|
+
| A job fails for good (`source_not_found`, `source_too_large`, `unsupported_format`, `invalid_request`, `max_attempts`) | Failed at once |
|
|
187
|
+
| No result within `timeoutSeconds` | Retried if `retry.onTimeout`, else failed with `timeout` |
|
|
188
|
+
| An earlier attempt succeeds after all | Counted: the document is done |
|
|
189
|
+
|
|
190
|
+
Parsers before 2.6 send no `errorCode`; the error text is used instead, and anything unclear is
|
|
191
|
+
retried. A run ends when nothing is pending or on the topic: `succeeded` while the failed share
|
|
192
|
+
stays within `failThreshold`, otherwise `completed_with_failures`.
|
|
193
|
+
|
|
194
|
+
**Pause** stops publishing; jobs already on the topic still finish. **Cancel** drops pending
|
|
195
|
+
documents and waits for the jobs on the topic (`cancelling`, then `cancelled`): Kafka messages
|
|
196
|
+
cannot be taken back. **Retry failed** sends the failed documents again with fresh attempts and
|
|
197
|
+
reopens a finished run.
|
|
198
|
+
|
|
199
|
+
## Reports
|
|
200
|
+
|
|
201
|
+
Every run has a report, from `qaechi-batch report <runId>`, `BatchClient.report()` or
|
|
202
|
+
`GET /runs/{runId}/report`:
|
|
203
|
+
|
|
204
|
+
| Format | |
|
|
205
|
+
|---|---|
|
|
206
|
+
| `json` | the summary: the run and its counts, failed share against `failThreshold`, failures grouped by `errorCode` with an example, counts per `docType`, the failed documents (the first 10,000) |
|
|
207
|
+
| `csv` | every document in manifest order: `seq`, `documentId`, `source`, `docType`, `status`, `attempt`, `jobId`, `resultId`, `groundedness`, `errorCode`, `error`, times |
|
|
208
|
+
| `html` | one page to read or attach: the summary, failures by code and type, the first 500 failed documents |
|
|
209
|
+
|
|
210
|
+
```console
|
|
211
|
+
$ qaechi-batch report archive-2019
|
|
212
|
+
run archive-2019
|
|
213
|
+
status completed_with_failures
|
|
214
|
+
documents 48210/48210 done in 2.0 h
|
|
215
|
+
failed 1197, skipped 1000, succeeded 46013
|
|
216
|
+
failed 2.48% (threshold 2.00%)
|
|
217
|
+
1100 source_not_found SourceError: source not found: 2019/0012.pdf
|
|
218
|
+
97 unsupported_format ValueError: unsupported format: .xyz
|
|
219
|
+
report s3://reports/batch/archive-2019/
|
|
220
|
+
$ qaechi-batch report archive-2019 --format csv -o failed.csv
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
With `QAECHI_BATCH_REPORT_URI` set (`s3://bucket/prefix` or a folder), the coordinator also writes
|
|
224
|
+
`report.json`, `items.csv` and `report.html` to `{uri}/{runId}/` when a run finishes, and sets the
|
|
225
|
+
run's `reportUri`. A report that cannot be written is tried again ten minutes later. Retry failed
|
|
226
|
+
reopens a run, and its report is written again when it ends again.
|
|
227
|
+
|
|
228
|
+
## Incremental runs
|
|
229
|
+
|
|
230
|
+
With `incremental: true` in the spec, a document that has not changed since its last successful
|
|
231
|
+
extraction is not sent again. It is `skipped` and keeps that extraction's `resultId`:
|
|
232
|
+
|
|
233
|
+
```yaml
|
|
234
|
+
incremental: true
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
A document counts as unchanged when its `documentId`, its `etag` or `sha256`, and its job request
|
|
238
|
+
(`docType`, `fields`, `lines`, `source`, ...) are all the same as at that success. Rows without
|
|
239
|
+
`etag` or `sha256` always run, and so does every document after a change to the fields asked for.
|
|
240
|
+
Folder manifests on S3 carry each object's ETag, so a nightly run over a bucket only sends new
|
|
241
|
+
and changed files. Successes of every run, incremental or not, are remembered
|
|
242
|
+
(`qaechi_batch_documents`), so the first incremental run can already skip.
|
|
243
|
+
|
|
244
|
+
## Metrics
|
|
245
|
+
|
|
246
|
+
With the `otel` extra and `OTEL_EXPORTER_OTLP_ENDPOINT` set, `serve` sends OpenTelemetry metrics
|
|
247
|
+
over OTLP/HTTP, like qaechi-parser (`QAECHI_OTEL=off` turns them off, `on` uses the SDK defaults).
|
|
248
|
+
No metric carries a runId, so the number of series stays small; per-run numbers are in the API
|
|
249
|
+
and the reports.
|
|
250
|
+
|
|
251
|
+
| Metric (Prometheus name) | |
|
|
252
|
+
|---|---|
|
|
253
|
+
| `qaechi_batch_jobs_published_total` | jobs sent to the job topic |
|
|
254
|
+
| `qaechi_batch_results_total{outcome}` | result events: `succeeded`, `retry`, `failed`, `stale`, `late`, `unknown` |
|
|
255
|
+
| `qaechi_batch_timeouts_total{outcome}` | jobs without a result in time: `retry` or `failed` |
|
|
256
|
+
| `qaechi_batch_runs_finished_total{status}` | runs that ended, by final status |
|
|
257
|
+
| `qaechi_batch_run_duration_seconds{status}` | histogram, start to end of a run |
|
|
258
|
+
| `qaechi_batch_reports_total{outcome}` | reports `written` or `failed` |
|
|
259
|
+
| `qaechi_batch_loop_restarts_total{loop}` | a background loop crashed and was restarted |
|
|
260
|
+
| `qaechi_batch_runs{status}` | gauge: runs not finished yet |
|
|
261
|
+
| `qaechi_batch_items_open{status}` | gauge: `pending` and `published` documents of those runs |
|
|
262
|
+
|
|
263
|
+
## Docker
|
|
264
|
+
|
|
265
|
+
```bash
|
|
266
|
+
docker build -t qaechi-batch .
|
|
267
|
+
docker run -p 127.0.0.1:3200:3200 --env-file .env qaechi-batch
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
The image has the `server`, `s3` and `otel` extras (`--build-arg EXTRAS=...` to change). For
|
|
271
|
+
the whole stack (Kafka, PostgreSQL, parser workers, sink, Grafana) use
|
|
272
|
+
[qaechi-stack](https://github.com/qaechi/qaechi-stack).
|
|
273
|
+
|
|
274
|
+
## Settings
|
|
275
|
+
|
|
276
|
+
| Variable | Default | |
|
|
277
|
+
|---|---|---|
|
|
278
|
+
| `QAECHI_BATCH_DATABASE_URL` | `QAECHI_DATABASE_URL` | PostgreSQL for runs and items (tables `qaechi_batch_*`, created on start) |
|
|
279
|
+
| `QAECHI_KAFKA_BOOTSTRAP_SERVERS` | | brokers, the same as the parser's |
|
|
280
|
+
| `QAECHI_KAFKA_TOPIC_JOBS` | `qaechi.parse.jobs` | where jobs are published |
|
|
281
|
+
| `QAECHI_KAFKA_TOPIC_RESULTS` | `qaechi.parse.results` | where results are read |
|
|
282
|
+
| `QAECHI_BATCH_MAX_IN_FLIGHT` | `1000` | jobs on the topic at once over all runs; each run also has `maxInFlight` |
|
|
283
|
+
| `QAECHI_BATCH_SOURCE_ROOT` | | the worker's source root, for absolute sources, folders and `validate` |
|
|
284
|
+
| `QAECHI_S3_ENDPOINT_URL` | | MinIO, R2 or another S3-compatible store |
|
|
285
|
+
| `QAECHI_KAFKA_CONF_*` | | any librdkafka setting, e.g. SASL |
|
|
286
|
+
| `QAECHI_BATCH_GROUP_ID` | `qaechi-batch` | consumer group for result events |
|
|
287
|
+
| `QAECHI_INTERNAL_TOKEN` | | required by `serve`; the client sends it |
|
|
288
|
+
| `QAECHI_BATCH_URL` | `http://127.0.0.1:3200` | where the client and CLI find the coordinator |
|
|
289
|
+
| `QAECHI_BATCH_REPORT_URI` | | where reports of finished runs are written: `s3://bucket/prefix` or a folder |
|
|
290
|
+
| `OTEL_EXPORTER_OTLP_ENDPOINT` | | OTLP/HTTP collector for metrics (extra `otel`); `OTEL_SERVICE_NAME` defaults to `qaechi-batch` |
|
|
291
|
+
|
|
292
|
+
Jobs go out a window at a time, never the whole manifest at once: pause and cancel act at once and
|
|
293
|
+
a large run does not hold back other work. Each job is `qb-{runId}-{seq}-a{attempt}` and carries
|
|
294
|
+
the `runId`, so results find their run.
|
|
295
|
+
|
|
296
|
+
## Requirements
|
|
297
|
+
|
|
298
|
+
Python 3.11 or later. The coordinator needs Kafka, PostgreSQL and qaechi-parser in queue mode;
|
|
299
|
+
2.6 or later sends the `errorCode` used for retries.
|
|
300
|
+
|
|
301
|
+
## License
|
|
302
|
+
|
|
303
|
+
Apache-2.0. See [LICENSE](LICENSE).
|