diff --git a/site/services/process.py b/site/services/process.py index 39b6fe8..c56d827 100644 --- a/site/services/process.py +++ b/site/services/process.py @@ -86,27 +86,21 @@ def run_pipeline(contract_id, order_ids, build_prompt_fn): "time_s": round(time.time() - t1, 1), } - # Apply ops to DB - applied_ops = [] - summary = {"added": 0, "updated": 0, "deleted": 0, "unresolved": 0} - for op in ops: - action = op.get("action", "UNRESOLVED") - summary[action.lower()] = summary.get(action.lower(), 0) + 1 - try: - if action == "ADD": - nr = op.get("new_row", {}) - spec_events.add_row(contract_id, sid, nr) - elif action == "UPDATE": - nr = op.get("new_row", {}) - nv = op.get("new_values", {}) - target = op.get("target_hash", "") - spec_events.update_row(contract_id, sid, target, nr, nv) - elif action == "DELETE": - target = op.get("target_hash", "") - spec_events.delete_row(contract_id, sid, target) - applied_ops.append(op) - except Exception: - summary["unresolved"] = summary.get("unresolved", 0) + 1 + # Apply ops to DB via apply_ops + try: + summary = spec_events.apply_ops( + contract_id, sid, s["document_id"], ops, prompt_id, result + ) + applied_ops = ops + except Exception as e: + summary = {"added": 0, "updated": 0, "deleted": 0, "unresolved": len(ops)} + applied_ops = [] + yield { + "type": "extract_error", + "supplement_id": sid, + "filename": filename, + "error": str(e), + } # Arithmetic check check_arithmetic(contract_id)