diff --git a/app/pipeline/file_manager.py b/app/pipeline/file_manager.py index fb62ef6..9524b4a 100644 --- a/app/pipeline/file_manager.py +++ b/app/pipeline/file_manager.py @@ -229,7 +229,7 @@ def check_dir_write_access( pass return ( False, - f"Недостаточно прав на запись/переименование в папке: {target_dir}. {exc}", + f"Недостаточно прав на запись/переименование/удаление в папке: {target_dir}. {exc}", ) diff --git a/app/pipeline/service.py b/app/pipeline/service.py index a40987c..2a8c9c7 100644 --- a/app/pipeline/service.py +++ b/app/pipeline/service.py @@ -82,10 +82,12 @@ def run_batch( run_context = create_run_context(input_dir=input_dir, samba_conn=samba_conn) checks = [ + (input_dir, "Входная папка (перемещение файлов)"), (run_context.run_dir, "Папка Out (текущий запуск)"), (run_context.processed_dir, "Папка Processed"), (run_context.error_dir, "Папка Err"), ] + preflight_labels: list[str] = [] for target_dir, label in checks: is_ok, write_error = check_dir_write_access( target_dir=target_dir, @@ -103,9 +105,17 @@ def run_batch( log_path="", messages=[write_error or f"Нет прав на запись в: {target_dir}"], ) + preflight_labels.append(label) + + messages.append( + "Проверка прав (чтение/запись/копирование/удаление) пройдена: " + + ", ".join(preflight_labels) + + "." + ) protocol_rows: list[ProtocolRow] = [] log_lines: list[str] = [] + log_lines.append(f"{_now()} | preflight access checks: ok") scan_result = scan_input_files(input_dir=input_dir, samba_conn=samba_conn) log_lines.append( @@ -180,6 +190,11 @@ def run_batch( if errors == 0 and partial == 0 else ("partial" if partial > 0 else "error") ) + messages.append( + _build_result_message( + status=status, processed=processed, partial=partial, errors=errors + ) + ) messages.extend(log_lines[-5:]) return BatchResult( status=status, @@ -332,3 +347,18 @@ def _upload_artifacts( def _now() -> str: return datetime.now().strftime("%Y-%m-%d %H:%M:%S") + + +def _build_result_message( + *, status: str, processed: int, partial: int, errors: int +) -> str: + if status == "success": + if processed > 0: + return f"Все успешно: обработано файлов {processed}." + return "Успешно: новых файлов для обработки нет." + if status == "partial": + return ( + "Частично успешно: " + f"успешно={processed}, частично={partial}, с ошибками={errors}." + ) + return f"Ошибка обработки: успешно={processed}, частично={partial}, с ошибками={errors}."