feat: PG-очередь — classify_status='processing' для crash recovery
This commit is contained in:
@@ -70,13 +70,21 @@ def list_pending(batch_id):
|
|||||||
|
|
||||||
|
|
||||||
def reset_classify_status(batch_id):
|
def reset_classify_status(batch_id):
|
||||||
"""Сбросить classify_status на 'pending' для всех документов батча."""
|
"""Сбросить classify_status на 'pending' для всех документов батча (включая 'processing' — crash recovery)."""
|
||||||
return execute(
|
return execute(
|
||||||
"UPDATE documents SET classify_status='pending', error_message=NULL WHERE batch_id=%s",
|
"UPDATE documents SET classify_status='pending', error_message=NULL WHERE batch_id=%s",
|
||||||
(batch_id,),
|
(batch_id,),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def set_classify_processing(doc_id):
|
||||||
|
"""Mark document as being processed (for crash recovery)."""
|
||||||
|
return execute(
|
||||||
|
"UPDATE documents SET classify_status='processing' WHERE id=%s",
|
||||||
|
(doc_id,),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def list_by_batch(batch_id):
|
def list_by_batch(batch_id):
|
||||||
"""All documents in a batch with classification fields."""
|
"""All documents in a batch with classification fields."""
|
||||||
return query(
|
return query(
|
||||||
|
|||||||
@@ -116,6 +116,7 @@ def classify_batch(batch_id):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
# Stage 3: LLM classification (only for remaining)
|
# Stage 3: LLM classification (only for remaining)
|
||||||
|
db_docs.set_classify_processing(doc["id"]) # crash recovery marker
|
||||||
result, raw, needed_fix = _call_llm_classify(text)
|
result, raw, needed_fix = _call_llm_classify(text)
|
||||||
json_total += 1
|
json_total += 1
|
||||||
if needed_fix:
|
if needed_fix:
|
||||||
|
|||||||
Reference in New Issue
Block a user