checkpoint
This commit is contained in:
@@ -28,6 +28,7 @@ from .tasks import (
|
||||
)
|
||||
from ..common.error_csv import download_scan_errors_csv_stream
|
||||
from ..common.track_commit_dispatch import dispatch_tracked_layouts_csv_commit
|
||||
from ..common.responses import normalize_commit_status_payload
|
||||
|
||||
router = APIRouter()
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -127,12 +128,12 @@ async def get_import_status(job_id: str):
|
||||
if task_result.state == "SUCCESS":
|
||||
result = task_result.result
|
||||
if isinstance(result, dict) and "status" in result:
|
||||
return result
|
||||
return normalize_commit_status_payload(result)
|
||||
return {"status": "finished", "result": result}
|
||||
|
||||
result = getattr(task_result, "result", None)
|
||||
if isinstance(result, dict) and result.get("status") in ("finished", "warning"):
|
||||
return result
|
||||
return normalize_commit_status_payload(result)
|
||||
|
||||
logger.warning("BOMs import task %s failed: state=%s", job_id, task_result.state)
|
||||
err_msg = None
|
||||
|
||||
@@ -62,8 +62,7 @@ def scan_file(self, job_id: str, config: str = None):
|
||||
try:
|
||||
with open(error_path, "w", encoding="utf-8") as f_err:
|
||||
for i, row in common_csv.iter_csv_rows(file_path):
|
||||
if i % 500 == 0:
|
||||
self.update_state(
|
||||
self.update_state(
|
||||
state="PROGRESS",
|
||||
meta={"current": i, "total": total_rows, "errors": error_count},
|
||||
)
|
||||
|
||||
@@ -22,6 +22,7 @@ from ..common.track_commit_dispatch import dispatch_tracked_layouts_csv_commit
|
||||
from .schemas import ImportJobResponse, CommitRequest
|
||||
from .tasks import scan_file, insert_valid_rows, JOB_TYPE, CRREG_IMPORT_REDIS_TTL
|
||||
from ..common import storage as common_storage
|
||||
from ..common.responses import normalize_commit_status_payload
|
||||
from ..common.error_csv import download_scan_errors_csv_stream
|
||||
|
||||
router = APIRouter()
|
||||
@@ -133,11 +134,11 @@ async def get_import_status(job_id: str):
|
||||
if task_result.state == "SUCCESS":
|
||||
result = task_result.result
|
||||
if isinstance(result, dict) and "status" in result:
|
||||
return result
|
||||
return normalize_commit_status_payload(result)
|
||||
return {"status": "finished", "result": result}
|
||||
|
||||
if isinstance(getattr(task_result, "result", None), dict) and task_result.result.get("status") in ("finished", "warning"):
|
||||
return task_result.result
|
||||
return normalize_commit_status_payload(task_result.result)
|
||||
|
||||
logger.warning("Cambio régimen/Regularización import task %s failed: state=%s", job_id, task_result.state)
|
||||
err_msg = None
|
||||
|
||||
@@ -75,8 +75,7 @@ def scan_file(self, job_id: str, model_target: str, config: str = None):
|
||||
|
||||
try:
|
||||
for i, row in common_csv_reader.iter_csv_rows(file_path, fieldnames=None):
|
||||
if i % 500 == 0:
|
||||
on_progress(i, total_rows)
|
||||
on_progress(i, total_rows)
|
||||
_norm_row(row, template_id)
|
||||
processed_rows += 1
|
||||
except Exception as e:
|
||||
|
||||
@@ -19,6 +19,7 @@ from core.security import get_current_user, validate_access_to_resource
|
||||
from api.v1.modules.core.tasks_tracking import track_and_dispatch
|
||||
|
||||
from ..common.track_commit_dispatch import dispatch_tracked_layouts_csv_commit
|
||||
from ..common.responses import normalize_commit_status_payload
|
||||
from .schemas import ImportJobResponse
|
||||
from .tasks import (
|
||||
scan_file,
|
||||
@@ -133,12 +134,12 @@ async def get_import_status(job_id: str):
|
||||
if task_result.state == "SUCCESS":
|
||||
result = task_result.result
|
||||
if isinstance(result, dict) and "status" in result:
|
||||
return result
|
||||
return normalize_commit_status_payload(result)
|
||||
return {"status": "finished", "result": result}
|
||||
|
||||
result = getattr(task_result, "result", None)
|
||||
if isinstance(result, dict) and result.get("status") in ("finished", "warning"):
|
||||
return result
|
||||
return normalize_commit_status_payload(result)
|
||||
|
||||
# Si Celery devolvió el resultado como string (p. ej. JSON), parsear y devolver como scan si aplica
|
||||
if isinstance(result, str):
|
||||
@@ -150,7 +151,7 @@ async def get_import_status(job_id: str):
|
||||
):
|
||||
return parsed
|
||||
if isinstance(parsed, dict) and parsed.get("status") in ("finished", "warning"):
|
||||
return parsed
|
||||
return normalize_commit_status_payload(parsed)
|
||||
except (json.JSONDecodeError, TypeError):
|
||||
pass
|
||||
|
||||
|
||||
@@ -84,8 +84,7 @@ def scan_file(self, job_id: str, config: str = None):
|
||||
try:
|
||||
with open(error_path, "w", encoding="utf-8") as f_err:
|
||||
for i, row in common_csv.iter_csv_rows(file_path, fieldnames=fieldnames):
|
||||
if i % 500 == 0:
|
||||
self.update_state(
|
||||
self.update_state(
|
||||
state="PROGRESS",
|
||||
meta={"current": i, "total": total_rows, "errors": error_count},
|
||||
)
|
||||
|
||||
@@ -19,6 +19,7 @@ from core.security import get_current_user, validate_access_to_resource
|
||||
from api.v1.modules.core.tasks_tracking import track_and_dispatch
|
||||
|
||||
from ..common.track_commit_dispatch import dispatch_tracked_layouts_csv_commit
|
||||
from ..common.responses import normalize_commit_status_payload
|
||||
from .schemas import ImportJobResponse
|
||||
from .tasks import (
|
||||
scan_file,
|
||||
@@ -135,13 +136,13 @@ async def get_import_status(job_id: str):
|
||||
if task_result.state == "SUCCESS":
|
||||
result = task_result.result
|
||||
if isinstance(result, dict) and "status" in result:
|
||||
return result
|
||||
return normalize_commit_status_payload(result)
|
||||
return {"status": "finished", "result": result}
|
||||
|
||||
# A veces Celery tiene el result disponible pero state aún no es SUCCESS; si el result es éxito, devolverlo
|
||||
result = getattr(task_result, "result", None)
|
||||
if isinstance(result, dict) and result.get("status") in ("finished", "warning"):
|
||||
return result
|
||||
return normalize_commit_status_payload(result)
|
||||
|
||||
logger.warning("CP import task %s failed: state=%s", job_id, task_result.state)
|
||||
err_msg = None
|
||||
|
||||
@@ -77,7 +77,7 @@ def _do_scan(job_id: str, progress_callback: Optional[Any] = None) -> Dict[str,
|
||||
try:
|
||||
with open(error_path, "w", encoding="utf-8") as f_err:
|
||||
for i, row in common_csv_reader.iter_csv_rows(file_path):
|
||||
if progress_callback and i % 500 == 0:
|
||||
if progress_callback:
|
||||
progress_callback(i, total_rows, error_count)
|
||||
|
||||
row_norm = row_from_template(row, common_normalize.normalize_header)
|
||||
|
||||
@@ -72,3 +72,36 @@ def commit_result(
|
||||
if error:
|
||||
out["error"] = error
|
||||
return out
|
||||
|
||||
|
||||
def normalize_commit_status_payload(d: Dict[str, Any]) -> Dict[str, Any]:
|
||||
"""
|
||||
Homogeneiza respuestas de commit CSV (finished / warning) al contrato usado por pedimentos:
|
||||
inserted, updated, skipped_*, skipped_details, skipped_summary, critical_reference_gaps,
|
||||
reference_state_ready. No modifica waiting_confirmation ni otros status.
|
||||
"""
|
||||
if not isinstance(d, dict):
|
||||
return d
|
||||
st = d.get("status")
|
||||
if st not in ("finished", "warning"):
|
||||
return d
|
||||
out = dict(d)
|
||||
out.setdefault("inserted", 0)
|
||||
out.setdefault("updated", 0)
|
||||
out.setdefault("skipped_invalid", 0)
|
||||
out.setdefault("skipped_missing_fk", 0)
|
||||
out.setdefault("skipped_duplicate", 0)
|
||||
out.setdefault("skipped_missing_invoice", 0)
|
||||
details = out.get("skipped_details")
|
||||
if not isinstance(details, list):
|
||||
out["skipped_details"] = []
|
||||
else:
|
||||
out["skipped_details"] = details
|
||||
out.setdefault("critical_reference_gaps", 0)
|
||||
if "reference_state_ready" not in out:
|
||||
out["reference_state_ready"] = out.get("critical_reference_gaps", 0) == 0
|
||||
if "skipped_summary" not in out:
|
||||
out["skipped_summary"] = (
|
||||
_summarize_reasons(out["skipped_details"], "reason") if out["skipped_details"] else []
|
||||
)
|
||||
return out
|
||||
|
||||
@@ -19,6 +19,7 @@ from core.security import get_current_user, validate_access_to_resource
|
||||
from api.v1.modules.core.tasks_tracking import track_and_dispatch
|
||||
|
||||
from ..common.track_commit_dispatch import dispatch_tracked_layouts_csv_commit
|
||||
from ..common.responses import normalize_commit_status_payload
|
||||
from .schemas import ImportJobResponse
|
||||
from .tasks import (
|
||||
scan_file,
|
||||
@@ -135,13 +136,13 @@ async def get_import_status(job_id: str):
|
||||
if task_result.state == "SUCCESS":
|
||||
result = task_result.result
|
||||
if isinstance(result, dict) and "status" in result:
|
||||
return result
|
||||
return normalize_commit_status_payload(result)
|
||||
return {"status": "finished", "result": result}
|
||||
|
||||
# A veces Celery tiene el result disponible pero state aún no es SUCCESS; si el result es éxito, devolverlo
|
||||
result = getattr(task_result, "result", None)
|
||||
if isinstance(result, dict) and result.get("status") in ("finished", "warning"):
|
||||
return result
|
||||
return normalize_commit_status_payload(result)
|
||||
|
||||
logger.warning("CB import task %s failed: state=%s", job_id, task_result.state)
|
||||
err_msg = None
|
||||
|
||||
@@ -88,7 +88,7 @@ def _do_scan(job_id: str, progress_callback: Optional[Any] = None) -> Dict[str,
|
||||
fieldnames=CUSTOMS_BROKERS_FIELDNAMES_ORDER,
|
||||
headerless_first_cell_values=CUSTOMS_BROKERS_HEADERLESS_FIRST_CELL,
|
||||
):
|
||||
if progress_callback and i % 500 == 0:
|
||||
if progress_callback:
|
||||
progress_callback(i, total_rows, error_count)
|
||||
|
||||
row_norm = row_from_template(row, common_normalize.normalize_header)
|
||||
|
||||
@@ -28,6 +28,7 @@ from .tasks import (
|
||||
DRV_IMPORT_REDIS_TTL,
|
||||
)
|
||||
from ..common.error_csv import download_scan_errors_csv_stream
|
||||
from ..common.responses import normalize_commit_status_payload
|
||||
|
||||
router = APIRouter()
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -113,6 +114,8 @@ async def get_import_status(job_id: str):
|
||||
raw = r.get(f"{DRV_IMPORT_STATUS_PREFIX}{job_id}")
|
||||
if raw:
|
||||
data = json.loads(raw.decode("utf-8"))
|
||||
if isinstance(data, dict) and data.get("status") in ("finished", "warning"):
|
||||
return normalize_commit_status_payload(data)
|
||||
return data
|
||||
except Exception as e:
|
||||
logger.debug(f"Drivers import: could not read status from Redis: {e}")
|
||||
@@ -131,12 +134,12 @@ async def get_import_status(job_id: str):
|
||||
if task_result.state == "SUCCESS":
|
||||
result = task_result.result
|
||||
if isinstance(result, dict) and "status" in result:
|
||||
return result
|
||||
return normalize_commit_status_payload(result)
|
||||
return {"status": "finished", "result": result}
|
||||
|
||||
result = getattr(task_result, "result", None)
|
||||
if isinstance(result, dict) and result.get("status") in ("finished", "warning"):
|
||||
return result
|
||||
return normalize_commit_status_payload(result)
|
||||
|
||||
logger.warning("Drivers import task %s failed: state=%s", job_id, task_result.state)
|
||||
err_msg = None
|
||||
|
||||
@@ -135,7 +135,7 @@ def _do_scan(job_id: str, progress_callback: Optional[Any] = None) -> Dict[str,
|
||||
dict_reader = csv.DictReader(f_in, fieldnames=headers, dialect=dialect)
|
||||
|
||||
for i, row in enumerate(dict_reader, start=1):
|
||||
if progress_callback and i % 500 == 0:
|
||||
if progress_callback:
|
||||
progress_callback(i, total_rows, error_count)
|
||||
|
||||
row_norm = row_from_template(row, common_normalize.normalize_header)
|
||||
|
||||
@@ -19,6 +19,7 @@ from core.security import get_current_user, validate_access_to_resource
|
||||
from api.v1.modules.core.tasks_tracking import track_and_dispatch
|
||||
|
||||
from ..common.track_commit_dispatch import dispatch_tracked_layouts_csv_commit
|
||||
from ..common.responses import normalize_commit_status_payload
|
||||
from .schemas import ImportJobResponse
|
||||
from .tasks import (
|
||||
scan_file,
|
||||
@@ -146,12 +147,12 @@ async def get_import_status(job_id: str):
|
||||
if task_result.state == "SUCCESS":
|
||||
result = task_result.result
|
||||
if isinstance(result, dict) and "status" in result:
|
||||
return result
|
||||
return normalize_commit_status_payload(result)
|
||||
return {"status": "finished", "result": result}
|
||||
|
||||
result = getattr(task_result, "result", None)
|
||||
if isinstance(result, dict) and result.get("status") in ("finished", "warning"):
|
||||
return result
|
||||
return normalize_commit_status_payload(result)
|
||||
|
||||
logger.warning("ER import task %s failed: state=%s", job_id, task_result.state)
|
||||
err_msg = None
|
||||
|
||||
@@ -66,7 +66,7 @@ def _do_scan(job_id: str, progress_callback: Optional[Any] = None) -> Dict[str,
|
||||
try:
|
||||
with open(error_path, "w", encoding="utf-8") as f_err:
|
||||
for i, row in common_csv_reader.iter_csv_rows(file_path):
|
||||
if progress_callback and i % 500 == 0:
|
||||
if progress_callback:
|
||||
progress_callback(i, total_rows, error_count)
|
||||
|
||||
row_norm = _norm_row(row)
|
||||
|
||||
@@ -25,6 +25,7 @@ from .schemas import ImportJobResponse, CommitRequest
|
||||
from .tasks import scan_file, insert_valid_rows, JOB_TYPE, EXP_IMPORT_REDIS_TTL
|
||||
from ..common import storage as common_storage
|
||||
from ..common.track_commit_dispatch import dispatch_tracked_layouts_csv_commit
|
||||
from ..common.responses import normalize_commit_status_payload
|
||||
|
||||
router = APIRouter()
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -138,11 +139,11 @@ async def get_import_status(job_id: str):
|
||||
if task_result.state == "SUCCESS":
|
||||
result = task_result.result
|
||||
if isinstance(result, dict) and "status" in result:
|
||||
return result
|
||||
return normalize_commit_status_payload(result)
|
||||
return {"status": "finished", "result": result}
|
||||
|
||||
if isinstance(getattr(task_result, "result", None), dict) and task_result.result.get("status") in ("finished", "warning"):
|
||||
return task_result.result
|
||||
return normalize_commit_status_payload(task_result.result)
|
||||
|
||||
logger.warning("Exportación import task %s failed: state=%s", job_id, task_result.state)
|
||||
err_msg = None
|
||||
|
||||
@@ -74,8 +74,7 @@ def scan_file(self, job_id: str, model_target: str, config: str = None):
|
||||
processed_rows = 0
|
||||
try:
|
||||
for i, row in common_csv_reader.iter_csv_rows(file_path, fieldnames=None):
|
||||
if i % 500 == 0:
|
||||
self.update_state(state="PROGRESS", meta={"current": i, "total": total_rows})
|
||||
self.update_state(state="PROGRESS", meta={"current": i, "total": total_rows})
|
||||
_norm_row(row, template_id)
|
||||
processed_rows += 1
|
||||
except Exception as e:
|
||||
|
||||
@@ -27,6 +27,7 @@ from .tasks import (
|
||||
)
|
||||
from .schemas import ImportJobResponse, ImportJobStatus, CommitRequest
|
||||
from ..common import storage as common_storage
|
||||
from ..common.responses import normalize_commit_status_payload
|
||||
from ..common.track_commit_dispatch import dispatch_tracked_layouts_csv_commit
|
||||
|
||||
router = APIRouter()
|
||||
@@ -150,7 +151,7 @@ async def get_import_status(job_id: str):
|
||||
if task_result.state == "SUCCESS":
|
||||
result = task_result.result
|
||||
if isinstance(result, dict) and "status" in result:
|
||||
return result
|
||||
return normalize_commit_status_payload(result)
|
||||
return {"status": "finished", "result": result}
|
||||
# FAILURE: obtener mensaje real (traceback, result o get(propagate=False))
|
||||
logger.warning("Import task %s failed: state=%s", job_id, task_result.state)
|
||||
|
||||
@@ -628,8 +628,7 @@ def _do_scan_file(self, job_id: str, model_target: str, config: Optional[str] =
|
||||
errors_detail = []
|
||||
error_lines_list: List[int] = []
|
||||
for i, row in enumerate(reader, start=1):
|
||||
if i % 1000 == 0:
|
||||
self.update_state(state="PROGRESS", meta={"current": i, "total": total_rows, "errors": len(error_lines_list)})
|
||||
self.update_state(state="PROGRESS", meta={"current": i, "total": total_rows, "errors": len(error_lines_list)})
|
||||
row_norm = row_from_template(row, "imp_def_series", normalize_header)
|
||||
warnings_list: List[Dict[str, Any]] = []
|
||||
row_errors = validate_row_series_impo_def(
|
||||
@@ -822,8 +821,7 @@ def _do_scan_file(self, job_id: str, model_target: str, config: Optional[str] =
|
||||
errors_detail = []
|
||||
error_lines_list: List[int] = []
|
||||
for i, row in enumerate(reader, start=1):
|
||||
if i % 1000 == 0:
|
||||
self.update_state(state="PROGRESS", meta={"current": i, "total": total_rows, "errors": len(error_lines_list)})
|
||||
self.update_state(state="PROGRESS", meta={"current": i, "total": total_rows, "errors": len(error_lines_list)})
|
||||
row_norm = row_from_template(row, "exp_def_series", normalize_header)
|
||||
warnings_list: List[Dict[str, Any]] = []
|
||||
row_errors = validate_row_series_expo(
|
||||
@@ -1004,8 +1002,7 @@ def _do_scan_file(self, job_id: str, model_target: str, config: Optional[str] =
|
||||
errors_detail = []
|
||||
error_lines_list: List[int] = []
|
||||
for i, row in enumerate(reader, start=1):
|
||||
if i % 1000 == 0:
|
||||
self.update_state(state="PROGRESS", meta={"current": i, "total": total_rows, "errors": len(error_lines_list)})
|
||||
self.update_state(state="PROGRESS", meta={"current": i, "total": total_rows, "errors": len(error_lines_list)})
|
||||
row_norm = row_from_template(row, "cmex_series", normalize_header)
|
||||
warnings_list: List[Dict[str, Any]] = []
|
||||
row_errors = validate_row_series_impo_def(
|
||||
@@ -1159,8 +1156,7 @@ def _do_scan_file(self, job_id: str, model_target: str, config: Optional[str] =
|
||||
errors_detail: List[Dict[str, Any]] = []
|
||||
error_lines_list: List[int] = []
|
||||
for i, row in enumerate(reader, start=1):
|
||||
if i % 1000 == 0:
|
||||
self.update_state(state="PROGRESS", meta={"current": i, "total": total_rows, "errors": len(error_lines_list)})
|
||||
self.update_state(state="PROGRESS", meta={"current": i, "total": total_rows, "errors": len(error_lines_list)})
|
||||
row_norm = row_from_template(row, "imp_temp_series", normalize_header)
|
||||
warnings_list: List[Dict[str, Any]] = []
|
||||
row_errors = validate_row_series_impo_temp(
|
||||
@@ -1495,8 +1491,7 @@ def _do_scan_file(self, job_id: str, model_target: str, config: Optional[str] =
|
||||
|
||||
with open(error_path, "w", encoding="utf-8") as f_err:
|
||||
for i, row in enumerate(rows_list, start=1):
|
||||
if i % 1000 == 0:
|
||||
self.update_state(state="PROGRESS", meta={"current": i, "total": total_rows, "errors": error_count})
|
||||
self.update_state(state="PROGRESS", meta={"current": i, "total": total_rows, "errors": error_count})
|
||||
row_norm = row_from_template(row, "imp_temp_details", normalize_header)
|
||||
row_errors = validate_row_partidas_impo_temp(
|
||||
row_norm,
|
||||
@@ -1806,8 +1801,7 @@ def _do_scan_file(self, job_id: str, model_target: str, config: Optional[str] =
|
||||
|
||||
with open(error_path, "w", encoding="utf-8") as f_err:
|
||||
for i, row in enumerate(rows_list, start=1):
|
||||
if i % 1000 == 0:
|
||||
self.update_state(state="PROGRESS", meta={"current": i, "total": total_rows, "errors": error_count})
|
||||
self.update_state(state="PROGRESS", meta={"current": i, "total": total_rows, "errors": error_count})
|
||||
row_norm = row_from_template(row, "imp_def_details", normalize_header)
|
||||
row_errors = validate_row_partidas_impo_def(
|
||||
row_norm,
|
||||
@@ -2373,8 +2367,7 @@ def _do_scan_file(self, job_id: str, model_target: str, config: Optional[str] =
|
||||
|
||||
with open(error_path, "w", encoding="utf-8") as f_err:
|
||||
for i, row in enumerate(rows_list, start=1):
|
||||
if i % 1000 == 0:
|
||||
self.update_state(state="PROGRESS", meta={"current": i, "total": total_rows, "errors": error_count})
|
||||
self.update_state(state="PROGRESS", meta={"current": i, "total": total_rows, "errors": error_count})
|
||||
row_norm = row_from_template(row, "cmex_details", normalize_header)
|
||||
row_errors = validate_row_partidas_impo_def(
|
||||
row_norm,
|
||||
@@ -2831,8 +2824,7 @@ def _do_scan_file(self, job_id: str, model_target: str, config: Optional[str] =
|
||||
+ "\n"
|
||||
)
|
||||
for i, row in enumerate(rows_list, start=1):
|
||||
if i % 1000 == 0:
|
||||
self.update_state(
|
||||
self.update_state(
|
||||
state="PROGRESS",
|
||||
meta={
|
||||
"current": i,
|
||||
@@ -3205,8 +3197,7 @@ def _do_scan_file(self, job_id: str, model_target: str, config: Optional[str] =
|
||||
|
||||
with open(error_path, "w", encoding="utf-8") as f_err:
|
||||
for i, row in enumerate(rows_list, start=1):
|
||||
if i % 1000 == 0:
|
||||
self.update_state(state="PROGRESS", meta={"current": i, "total": total_rows, "errors": error_count})
|
||||
self.update_state(state="PROGRESS", meta={"current": i, "total": total_rows, "errors": error_count})
|
||||
row_norm = row_from_template(row, "imp_def_header", normalize_header)
|
||||
warnings_row = []
|
||||
row_errors = validate_row_encabezados_impo_def(
|
||||
@@ -3582,8 +3573,7 @@ def _do_scan_file(self, job_id: str, model_target: str, config: Optional[str] =
|
||||
|
||||
with open(error_path, "w", encoding="utf-8") as f_err:
|
||||
for i, row in enumerate(rows_list, start=1):
|
||||
if i % 1000 == 0:
|
||||
self.update_state(state="PROGRESS", meta={"current": i, "total": total_rows, "errors": error_count})
|
||||
self.update_state(state="PROGRESS", meta={"current": i, "total": total_rows, "errors": error_count})
|
||||
row_norm = row_from_template(row, "exp_def_header", normalize_header)
|
||||
warnings_row = []
|
||||
row_errors = validate_row_encabezados_expo(
|
||||
@@ -3798,8 +3788,7 @@ def _do_scan_file(self, job_id: str, model_target: str, config: Optional[str] =
|
||||
with CoreSessionLocal() as session:
|
||||
with open(error_path, "w", encoding="utf-8") as f_err:
|
||||
for i, row in enumerate(rows_list, start=1):
|
||||
if i % 1000 == 0:
|
||||
self.update_state(
|
||||
self.update_state(
|
||||
state="PROGRESS",
|
||||
meta={"current": i, "total": total_rows, "errors": error_count},
|
||||
)
|
||||
@@ -3949,12 +3938,11 @@ def _do_scan_file(self, job_id: str, model_target: str, config: Optional[str] =
|
||||
|
||||
for i, row in enumerate(reader, start=1):
|
||||
# Check for Progress Update
|
||||
if i % 1000 == 0:
|
||||
self.update_state(state='PROGRESS', meta={
|
||||
'current': i,
|
||||
'total': total_rows,
|
||||
'errors': error_count
|
||||
})
|
||||
self.update_state(state='PROGRESS', meta={
|
||||
'current': i,
|
||||
'total': total_rows,
|
||||
'errors': error_count
|
||||
})
|
||||
|
||||
# Solo columnas de la plantilla (respetar plantilla tal cual)
|
||||
row_norm = row_from_template(row, template_id, normalize_header)
|
||||
|
||||
@@ -28,6 +28,7 @@ from .tasks import (
|
||||
)
|
||||
from ..common.error_csv import download_scan_errors_csv_stream
|
||||
from ..common.track_commit_dispatch import dispatch_tracked_layouts_csv_commit
|
||||
from ..common.responses import normalize_commit_status_payload
|
||||
|
||||
router = APIRouter()
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -131,12 +132,12 @@ async def get_import_status(job_id: str):
|
||||
if task_result.state == "SUCCESS":
|
||||
result = task_result.result
|
||||
if isinstance(result, dict) and "status" in result:
|
||||
return result
|
||||
return normalize_commit_status_payload(result)
|
||||
return {"status": "finished", "result": result}
|
||||
|
||||
result = getattr(task_result, "result", None)
|
||||
if isinstance(result, dict) and result.get("status") in ("finished", "warning"):
|
||||
return result
|
||||
return normalize_commit_status_payload(result)
|
||||
|
||||
# Si Celery devolvió el resultado como string (p. ej. JSON), parsear y devolver como scan si aplica
|
||||
if isinstance(result, str):
|
||||
@@ -148,7 +149,7 @@ async def get_import_status(job_id: str):
|
||||
):
|
||||
return parsed
|
||||
if isinstance(parsed, dict) and parsed.get("status") in ("finished", "warning"):
|
||||
return parsed
|
||||
return normalize_commit_status_payload(parsed)
|
||||
except (json.JSONDecodeError, TypeError):
|
||||
pass
|
||||
|
||||
|
||||
@@ -94,8 +94,7 @@ def scan_file(self, job_id: str, config: str = None):
|
||||
try:
|
||||
with open(error_path, "w", encoding="utf-8") as f_err:
|
||||
for i, row in common_csv.iter_csv_rows(file_path, fieldnames=fieldnames):
|
||||
if i % 500 == 0:
|
||||
self.update_state(
|
||||
self.update_state(
|
||||
state="PROGRESS",
|
||||
meta={"current": i, "total": total_rows, "errors": error_count},
|
||||
)
|
||||
|
||||
@@ -19,6 +19,7 @@ from core.security import get_current_user, validate_access_to_resource
|
||||
from api.v1.modules.core.tasks_tracking import track_and_dispatch
|
||||
|
||||
from ..common.track_commit_dispatch import dispatch_tracked_layouts_csv_commit
|
||||
from ..common.responses import normalize_commit_status_payload
|
||||
from .schemas import ImportJobResponse
|
||||
from .tasks import (
|
||||
scan_file,
|
||||
@@ -143,12 +144,12 @@ async def get_import_status(job_id: str):
|
||||
if task_result.state == "SUCCESS":
|
||||
result = task_result.result
|
||||
if isinstance(result, dict) and "status" in result:
|
||||
return result
|
||||
return normalize_commit_status_payload(result)
|
||||
return {"status": "finished", "result": result}
|
||||
|
||||
result = getattr(task_result, "result", None)
|
||||
if isinstance(result, dict) and result.get("status") in ("finished", "warning"):
|
||||
return result
|
||||
return normalize_commit_status_payload(result)
|
||||
|
||||
logger.warning("Pedimentos import task %s failed: state=%s", job_id, task_result.state)
|
||||
err_msg = None
|
||||
|
||||
@@ -99,7 +99,7 @@ def _do_scan(job_id: str, progress_callback: Optional[Any] = None) -> Dict[str,
|
||||
try:
|
||||
with open(error_path, "w", encoding="utf-8") as f_err:
|
||||
for i, row in common_csv_reader.iter_csv_rows(file_path, fieldnames=fieldnames):
|
||||
if progress_callback and i % 500 == 0:
|
||||
if progress_callback:
|
||||
progress_callback(i, total_rows, error_count)
|
||||
|
||||
row_norm = _norm_row(row)
|
||||
|
||||
@@ -30,6 +30,7 @@ from .tasks import (
|
||||
TRL_IMPORT_REDIS_TTL,
|
||||
)
|
||||
from ..common.error_csv import download_scan_errors_csv_stream
|
||||
from ..common.responses import normalize_commit_status_payload
|
||||
|
||||
router = APIRouter()
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -132,6 +133,8 @@ async def get_import_status(job_id: str):
|
||||
raw = r.get(f"{TRL_IMPORT_STATUS_PREFIX}{job_id}")
|
||||
if raw:
|
||||
data = json.loads(raw.decode("utf-8"))
|
||||
if isinstance(data, dict) and data.get("status") in ("finished", "warning"):
|
||||
return normalize_commit_status_payload(data)
|
||||
return data
|
||||
except Exception as e:
|
||||
logger.debug(f"Trailers import: could not read status from Redis: {e}")
|
||||
@@ -150,12 +153,12 @@ async def get_import_status(job_id: str):
|
||||
if task_result.state == "SUCCESS":
|
||||
result = task_result.result
|
||||
if isinstance(result, dict) and "status" in result:
|
||||
return result
|
||||
return normalize_commit_status_payload(result)
|
||||
return {"status": "finished", "result": result}
|
||||
|
||||
result = getattr(task_result, "result", None)
|
||||
if isinstance(result, dict) and result.get("status") in ("finished", "warning"):
|
||||
return result
|
||||
return normalize_commit_status_payload(result)
|
||||
|
||||
logger.warning("Trailers import task %s failed: state=%s", job_id, task_result.state)
|
||||
err_msg = None
|
||||
|
||||
@@ -121,7 +121,7 @@ def _do_scan(job_id: str, progress_callback: Optional[Any] = None) -> Dict[str,
|
||||
dict_reader = csv.DictReader(f_in, fieldnames=headers, dialect=dialect)
|
||||
|
||||
for i, row in enumerate(dict_reader, start=1):
|
||||
if progress_callback and i % 500 == 0:
|
||||
if progress_callback:
|
||||
progress_callback(i, total_rows, error_count)
|
||||
|
||||
row_norm = row_from_template(row, common_normalize.normalize_header)
|
||||
|
||||
@@ -30,6 +30,7 @@ from .tasks import (
|
||||
TRP_IMPORT_REDIS_TTL,
|
||||
)
|
||||
from ..common.error_csv import download_scan_errors_csv_stream
|
||||
from ..common.responses import normalize_commit_status_payload
|
||||
|
||||
router = APIRouter()
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -132,6 +133,8 @@ async def get_import_status(job_id: str):
|
||||
raw = r.get(f"{TRP_IMPORT_STATUS_PREFIX}{job_id}")
|
||||
if raw:
|
||||
data = json.loads(raw.decode("utf-8"))
|
||||
if isinstance(data, dict) and data.get("status") in ("finished", "warning"):
|
||||
return normalize_commit_status_payload(data)
|
||||
return data
|
||||
except Exception as e:
|
||||
logger.debug("Transportistas import: could not read status from Redis: %s", e)
|
||||
@@ -150,12 +153,12 @@ async def get_import_status(job_id: str):
|
||||
if task_result.state == "SUCCESS":
|
||||
result = task_result.result
|
||||
if isinstance(result, dict) and "status" in result:
|
||||
return result
|
||||
return normalize_commit_status_payload(result)
|
||||
return {"status": "finished", "result": result}
|
||||
|
||||
result = getattr(task_result, "result", None)
|
||||
if isinstance(result, dict) and result.get("status") in ("finished", "warning"):
|
||||
return result
|
||||
return normalize_commit_status_payload(result)
|
||||
|
||||
logger.warning("Transportistas import task %s failed: state=%s", job_id, task_result.state)
|
||||
err_msg = None
|
||||
|
||||
@@ -79,7 +79,7 @@ def _do_scan(job_id: str, progress_callback: Optional[Any] = None) -> Dict[str,
|
||||
try:
|
||||
with open(error_path, "w", encoding="utf-8") as f_err:
|
||||
for i, row in common_csv_reader.iter_csv_rows(file_path):
|
||||
if progress_callback and i % 500 == 0:
|
||||
if progress_callback:
|
||||
progress_callback(i, total_rows, error_count)
|
||||
|
||||
row_norm = row_from_template(row, common_normalize.normalize_header)
|
||||
|
||||
@@ -19,6 +19,7 @@ from core.security import get_current_user, validate_access_to_resource
|
||||
from api.v1.modules.core.tasks_tracking import track_and_dispatch
|
||||
|
||||
from ..common.track_commit_dispatch import dispatch_tracked_layouts_csv_commit
|
||||
from ..common.responses import normalize_commit_status_payload
|
||||
from .schemas import ImportJobResponse
|
||||
from .tasks import (
|
||||
scan_file,
|
||||
@@ -138,12 +139,12 @@ async def get_import_status(job_id: str):
|
||||
if task_result.state == "SUCCESS":
|
||||
result = task_result.result
|
||||
if isinstance(result, dict) and "status" in result:
|
||||
return result
|
||||
return normalize_commit_status_payload(result)
|
||||
return {"status": "finished", "result": result}
|
||||
|
||||
result = getattr(task_result, "result", None)
|
||||
if isinstance(result, dict) and result.get("status") in ("finished", "warning"):
|
||||
return result
|
||||
return normalize_commit_status_payload(result)
|
||||
|
||||
logger.warning("FA import task %s failed: state=%s", job_id, task_result.state)
|
||||
err_msg = None
|
||||
|
||||
@@ -68,7 +68,7 @@ def _do_scan(job_id: str, progress_callback: Optional[Any] = None) -> Dict[str,
|
||||
try:
|
||||
with open(error_path, "w", encoding="utf-8") as f_err:
|
||||
for i, row in common_csv_reader.iter_csv_rows(file_path):
|
||||
if progress_callback and i % 500 == 0:
|
||||
if progress_callback:
|
||||
progress_callback(i, total_rows, error_count)
|
||||
|
||||
warn = validate_row_desfase_fa(row, i)
|
||||
|
||||
@@ -30,6 +30,7 @@ from .tasks import (
|
||||
VEHL_IMPORT_REDIS_TTL,
|
||||
)
|
||||
from ..common.error_csv import download_scan_errors_csv_stream
|
||||
from ..common.responses import normalize_commit_status_payload
|
||||
|
||||
router = APIRouter()
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -131,6 +132,8 @@ async def get_import_status(job_id: str):
|
||||
raw = r.get(f"{VEHL_IMPORT_STATUS_PREFIX}{job_id}")
|
||||
if raw:
|
||||
data = json.loads(raw.decode("utf-8"))
|
||||
if isinstance(data, dict) and data.get("status") in ("finished", "warning"):
|
||||
return normalize_commit_status_payload(data)
|
||||
return data
|
||||
except Exception as e:
|
||||
logger.debug(f"Vehicles import: could not read status from Redis: {e}")
|
||||
@@ -149,12 +152,12 @@ async def get_import_status(job_id: str):
|
||||
if task_result.state == "SUCCESS":
|
||||
result = task_result.result
|
||||
if isinstance(result, dict) and "status" in result:
|
||||
return result
|
||||
return normalize_commit_status_payload(result)
|
||||
return {"status": "finished", "result": result}
|
||||
|
||||
result = getattr(task_result, "result", None)
|
||||
if isinstance(result, dict) and result.get("status") in ("finished", "warning"):
|
||||
return result
|
||||
return normalize_commit_status_payload(result)
|
||||
|
||||
logger.warning("Vehicles import task %s failed: state=%s", job_id, task_result.state)
|
||||
err_msg = None
|
||||
|
||||
@@ -92,7 +92,7 @@ def _do_scan(job_id: str, progress_callback: Optional[Any] = None) -> Dict[str,
|
||||
try:
|
||||
with open(error_path, "w", encoding="utf-8") as f_err:
|
||||
for i, row in common_csv_reader.iter_csv_rows(file_path):
|
||||
if progress_callback and i % 500 == 0:
|
||||
if progress_callback:
|
||||
progress_callback(i, total_rows, error_count)
|
||||
|
||||
row_norm = row_from_template(row, common_normalize.normalize_header)
|
||||
|
||||
Reference in New Issue
Block a user