From bb10e6fc899afc80e1e0b8cc1cabc168ad183cf0 Mon Sep 17 00:00:00 2001 From: Brandon Thomas Date: Sun, 12 Sep 2021 17:42:47 -0400 Subject: [PATCH] add temp file deletion for a few w2l inference error cases too --- src/w2l_inference_job.rs | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/w2l_inference_job.rs b/src/w2l_inference_job.rs index 98bfa2d327..a7d29b6aa6 100644 --- a/src/w2l_inference_job.rs +++ b/src/w2l_inference_job.rs @@ -551,7 +551,7 @@ async fn process_job(inferencer: &Inferencer, job: &W2lInferenceJobRecord) -> An info!("Is image? {}", is_image); info!("Running W2L inference..."); - inferencer.w2l_inference.execute( + let inference_result = inferencer.w2l_inference.execute( &model_fs_path, &audio_fs_path, &end_bump_fs_path, @@ -561,7 +561,14 @@ async fn process_job(inferencer: &Inferencer, job: &W2lInferenceJobRecord) -> An &output_video_fs_path, false, false - )?; + ); + + if let Err(e) = inference_result { + safe_delete_temp_file(&audio_fs_path); + safe_delete_temp_file(&output_video_fs_path); + safe_delete_temp_directory(&temp_dir); + return Err(e); + } info!("Output filename: {:?}", &output_video_fs_path); @@ -591,11 +598,18 @@ async fn process_job(inferencer: &Inferencer, job: &W2lInferenceJobRecord) -> An .as_deref() .unwrap_or("application/octet-stream"); - inferencer.public_bucket_client.upload_filename_with_content_type( + let upload_result = inferencer.public_bucket_client.upload_filename_with_content_type( &result_object_path, &output_video_fs_path, original_mime_type) - .await?; + .await; + + if let Err(e) = upload_result { + safe_delete_temp_file(&audio_fs_path); + safe_delete_temp_file(&output_video_fs_path); + safe_delete_temp_directory(&temp_dir); + return Err(e); + } safe_delete_temp_file(&output_video_fs_path);