improve the OCR pipeline processing and outputs formatting
This commit is contained in:
@@ -74,7 +74,7 @@ class Watcher:
|
||||
if self.running:
|
||||
return
|
||||
|
||||
self.run_id = self.db.start_run()
|
||||
self.run_id, _ = self.db.start_run()
|
||||
self.running = True
|
||||
|
||||
self.handler = ScreenshotHandler(self._process_file)
|
||||
@@ -112,29 +112,14 @@ class Watcher:
|
||||
logger.error("watch_process_failed", path=str(path), error=str(e))
|
||||
failed += 1
|
||||
|
||||
self.db.complete_run(
|
||||
time.strftime("%Y-%m-%d"),
|
||||
self.run_id,
|
||||
{"total": processed, "successful": processed, "failed": failed, "chunks": 0},
|
||||
)
|
||||
if self.run_id is not None:
|
||||
self.db.complete_run(self.run_id, {"total": processed + failed, "successful": processed, "failed": failed, "chunks": 0})
|
||||
logger.info("watcher_stopped", run_id=self.run_id, processed=processed, failed=failed)
|
||||
|
||||
def _process_file(self, path: Path) -> None:
|
||||
from ocr_pipeline.ocr.engine import compute_image_hash
|
||||
|
||||
file_hash = compute_image_hash(path)
|
||||
if self.db.is_processed(file_hash, path):
|
||||
logger.debug("file_already_processed", path=str(path))
|
||||
return
|
||||
|
||||
logger.info("processing_new_file", path=str(path))
|
||||
# The pipeline owns deduplication and database writes, preventing double marks.
|
||||
self.process_callback(path)
|
||||
self.db.mark_processed(
|
||||
file_hash=file_hash,
|
||||
path=str(path),
|
||||
timestamp=time.time(),
|
||||
run_id=self.run_id,
|
||||
)
|
||||
|
||||
def stop(self) -> None:
|
||||
self.running = False
|
||||
|
||||
Reference in New Issue
Block a user