Group work items into batches, respecting batch_size as a request count limit. Each work item stays whole (all its chunks in one batch). A batch may exceed ``batch_size`` when a single file has more chunks than the limit.
(
work_items: list[WorkItem],
batch_size: int,
)
| 253 | |
| 254 | |
| 255 | def group_work_items( |
| 256 | work_items: list[WorkItem], |
| 257 | batch_size: int, |
| 258 | ) -> list[list[WorkItem]]: |
| 259 | """Group work items into batches, respecting batch_size as a request count limit. |
| 260 | |
| 261 | Each work item stays whole (all its chunks in one batch). A batch may |
| 262 | exceed ``batch_size`` when a single file has more chunks than the limit. |
| 263 | """ |
| 264 | batches: list[list[WorkItem]] = [] |
| 265 | current: list[WorkItem] = [] |
| 266 | current_size = 0 |
| 267 | for item in work_items: |
| 268 | n = item.prepared.n_chunks |
| 269 | if current and current_size + n > batch_size: |
| 270 | batches.append(current) |
| 271 | current = [] |
| 272 | current_size = 0 |
| 273 | current.append(item) |
| 274 | current_size += n |
| 275 | if current: |
| 276 | batches.append(current) |
| 277 | return batches |
| 278 | |
| 279 | |
| 280 | def _prep_stats(prepared: PreparedFile) -> ExtractionStats: |
no outgoing calls