Adiciona limpeza de arquivos apos sucesso ou falha

This commit is contained in:
LeoMortari
2025-10-29 23:58:06 -03:00
parent ae8b228ea1
commit 87c6a5e27c
2 changed files with 20 additions and 20 deletions

View File

@@ -38,7 +38,7 @@ class MediaPreparer:
existing_children = list(workspace_dir.iterdir()) existing_children = list(workspace_dir.iterdir())
if existing_children: if existing_children:
logger.info("Limpando workspace existente para %s", sanitized_name) logger.info("Limpando workspace existente para %s", sanitized_name)
# remove_paths(existing_children) remove_paths(existing_children)
destination_name = f"{sanitized_name}{source_path.suffix.lower()}" destination_name = f"{sanitized_name}{source_path.suffix.lower()}"
working_video_path = workspace_dir / destination_name working_video_path = workspace_dir / destination_name
@@ -46,9 +46,9 @@ class MediaPreparer:
logger.info("Cópia do vídeo criada em %s", working_video_path) logger.info("Cópia do vídeo criada em %s", working_video_path)
output_dir = ensure_workspace(self.settings.outputs_dir, sanitized_name) output_dir = ensure_workspace(self.settings.outputs_dir, sanitized_name)
# existing_outputs = list(output_dir.iterdir()) existing_outputs = list(output_dir.iterdir())
# if existing_outputs: if existing_outputs:
# remove_paths(existing_outputs) remove_paths(existing_outputs)
audio_path = workspace_dir / "audio.wav" audio_path = workspace_dir / "audio.wav"
extract_audio_to_wav(working_video_path, audio_path) extract_audio_to_wav(working_video_path, audio_path)

View File

@@ -221,24 +221,24 @@ class VideoPipeline:
def _handle_failure(self, context: PipelineContext, exc: Exception) -> Dict[str, Any]: def _handle_failure(self, context: PipelineContext, exc: Exception) -> Dict[str, Any]:
logger.error("Erro na pipeline: %s", exc) logger.error("Erro na pipeline: %s", exc)
# cleanup_targets: List[Path] = [] cleanup_targets: List[Path] = []
# if context.workspace: if context.workspace:
# cleanup_targets.append(context.workspace.workspace_dir) cleanup_targets.append(context.workspace.workspace_dir)
# cleanup_targets.append(context.workspace.output_dir) cleanup_targets.append(context.workspace.output_dir)
# original_path = context.workspace.source_path original_path = context.workspace.source_path
# if original_path.exists(): if original_path.exists():
# cleanup_targets.append(original_path) cleanup_targets.append(original_path)
# else: else:
# sanitized = sanitize_filename(Path(context.job.filename).stem) sanitized = sanitize_filename(Path(context.job.filename).stem)
# job_output_dir = self.settings.outputs_dir / sanitized job_output_dir = self.settings.outputs_dir / sanitized
# if job_output_dir.exists(): if job_output_dir.exists():
# cleanup_targets.append(job_output_dir) cleanup_targets.append(job_output_dir)
# original_path = self.settings.videos_dir / context.job.filename original_path = self.settings.videos_dir / context.job.filename
# if original_path.exists(): if original_path.exists():
# cleanup_targets.append(original_path) cleanup_targets.append(original_path)
# remove_paths(cleanup_targets) remove_paths(cleanup_targets)
return { return {
"hasError": True, "hasError": True,