diff --git a/deploy/db/documents.py b/deploy/db/documents.py index 5068932..cf2ccdb 100644 --- a/deploy/db/documents.py +++ b/deploy/db/documents.py @@ -61,6 +61,14 @@ def list_pending(batch_id): ) +def reset_classify_status(batch_id): + """Сбросить classify_status на 'pending' для всех документов батча.""" + return execute( + "UPDATE documents SET classify_status='pending', error_message=NULL WHERE batch_id=%s AND status='parsed'", + (batch_id,), + ) + + def list_by_batch(batch_id): """All documents in a batch with classification fields.""" return query( diff --git a/deploy/services/classify.py b/deploy/services/classify.py index 2d0d38c..7064fa2 100644 --- a/deploy/services/classify.py +++ b/deploy/services/classify.py @@ -55,11 +55,13 @@ def _call_llm_classify(header_text): def classify_batch(batch_id): """ - Классифицировать все pending-документы в batch. - Вызывается из эндпоинта POST /api/classify-batch. + Классифицировать все документы в batch. + Сбрасывает статус на 'pending' для всех перед началом. Параллельно (ThreadPoolExecutor) обрабатывает до MAX_WORKERS документов. Возвращает {ok, total, done, failed}. """ + # Сбросить статус — allow re-classify after file changes + db_docs.reset_classify_status(batch_id) pending = db_docs.list_pending(batch_id) if not pending: return {"ok": False, "error": "no pending documents"}