MCPcopy Create free account
hub / github.com/chatdoc-com/OCRFlux / initialize_queue

Method initialize_queue

ocrflux/work_queue.py:251–278  ·  view source on GitHub ↗

Load the work queue from the local index file and initialize it for processing. Removes already completed work items and randomizes the order.

(self)

Source from the content-addressed store, hash-verified

249 await asyncio.to_thread(upload_zstd_csv_local, self._index_path, combined_lines)
250
251 async def initialize_queue(self) -> int:
252 """
253 Load the work queue from the local index file and initialize it for processing.
254 Removes already completed work items and randomizes the order.
255 """
256 # 1) Read the index
257 work_queue_lines = await asyncio.to_thread(download_zstd_csv_local, self._index_path)
258 work_queue = {parts[0]: parts[1:] for line in work_queue_lines if (parts := line.strip().split(",")) and line.strip()}
259
260 # 2) Determine which items are completed by scanning local results/*.jsonl
261 if not os.path.isdir(self._results_dir):
262 os.makedirs(self._results_dir, exist_ok=True)
263 done_work_items = [f for f in os.listdir(self._results_dir) if f.startswith("output_") and f.endswith(".jsonl")]
264 done_work_hashes = {fn[len("output_") : -len(".jsonl")] for fn in done_work_items}
265
266 # 3) Filter out completed items
267 remaining_work_hashes = set(work_queue) - done_work_hashes
268 remaining_items = [WorkItem(hash=hash_, work_paths=work_queue[hash_]) for hash_ in remaining_work_hashes]
269 random.shuffle(remaining_items)
270
271 # 4) Initialize our in-memory queue
272 self._queue = asyncio.Queue()
273 for item in remaining_items:
274 await self._queue.put(item)
275
276 logger.info(f"Initialized local queue with {self._queue.qsize()} work items")
277
278 return self._queue.qsize()
279
280 async def is_completed(self, work_hash: str) -> bool:
281 """

Callers 1

mainFunction · 0.95

Calls 1

WorkItemClass · 0.85

Tested by

no test coverage detected