fix: multi-worker translation status and OCR fallback handling

Translation status (multi-worker support):
- Add filesystem lock files (.translating) to track in-progress translations
- Check lock files in /status API when job_state not found in current worker
- Remove lock files on translation success or failure

OCR fallback fix:
- Fix empty pages when layout analysis fails but OCR succeeds
- Change 'enhanced_results' in ocr_results to ocr_results.get('enhanced_results')
- This ensures fallback to text_regions when enhanced_results is empty list

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
egg
2025-12-14 16:36:36 +08:00
parent 1c37585be2
commit 3ccbdb8394
4 changed files with 36 additions and 3 deletions

View File

@@ -343,9 +343,26 @@ async def get_translation_status(
job_state = translation_service.get_job_state(task_id)
if not job_state:
# No active job - check if any completed translations exist
# No active job in this worker - check filesystem for status
if task.result_json_path:
result_dir = Path(task.result_json_path).parent
# Check for in-progress translation (lock file exists)
lock_files = list(result_dir.glob("*.translating"))
if lock_files:
# Translation is in progress (possibly in another worker)
latest_lock = max(lock_files, key=lambda f: f.stat().st_mtime)
# Extract language from lock filename: {filename}_translated_{lang}.translating
lock_stem = latest_lock.stem # e.g., "scan_translated_en"
lang = lock_stem.split("_translated_")[-1] if "_translated_" in lock_stem else "unknown"
return TranslationStatusResponse(
task_id=task_id,
status=TranslationStatusEnum.TRANSLATING,
target_lang=lang,
progress=TranslationProgress(percentage=50.0) # Approximate progress
)
# Check for completed translations
translated_files = list(result_dir.glob("*_translated_*.json"))
if translated_files:
# Return completed status for the most recent translation