From ab04d0b1971647a451005e64e1abdd30e645ab5b Mon Sep 17 00:00:00 2001 From: "Gustavo H. X. Shiroma" Date: Sun, 17 Mar 2024 12:28:47 -0700 Subject: [PATCH 1/3] remove RTC-S1 products if at least one child process fails --- src/rtc/rtc_s1.py | 36 +++++++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/src/rtc/rtc_s1.py b/src/rtc/rtc_s1.py index 78f6384..e62caec 100755 --- a/src/rtc/rtc_s1.py +++ b/src/rtc/rtc_s1.py @@ -6,6 +6,7 @@ import logging import multiprocessing import os +import glob import subprocess import time import yaml @@ -592,11 +593,36 @@ def run_parallel(cfg: RunConfig, logfile_path, flag_logger_full_format): list_burst_id = list(cfg.bursts.keys()) for index_child, processing_result in \ enumerate(processing_result_list): - if processing_result != 0: - msg_failed_child_proc += ( - f'"{burst_runconfig_list[index_child]}"' - ' for burst ID ' - f'"{list_burst_id[index_child]}"\n') + + burst_id = list_burst_id[index_child] + output_dir_bursts = os.path.join(output_dir, burst_id) + + # Conservative change to avoid breaking OPERA RTC-S1 + # production. If there's at least one unsuccessful + # product, stop execution and delete ALL processed + # products to avoid sending half-empty products to the DAAC + # Do not delete log files + for ext in ['h5', 'tif', 'png']: + for f in glob.glob(os.path.join(output_dir_bursts, f'*{ext}')): + os.remove(f) + + # if output burst directory is empty, delete it + if (os.path.isdir(output_dir_bursts) and + len(os.listdir(output_dir_bursts)) == 0): + os.rmdir(output_dir_bursts) + + if processing_result == 0: + continue + + msg_failed_child_proc += ( + f'"{burst_runconfig_list[index_child]}" for burst ID ' + f'"{burst_id}"\n') + + # if output directory is empty, delete it + if (os.path.isdir(output_dir) and + len(os.listdir(output_dir)) == 0): + os.rmdir(output_dir) + raise RuntimeError(msg_failed_child_proc) lookside = None From 65053862e5a39a473bfa8491858922723dfb249e Mon Sep 17 00:00:00 2001 From: "Gustavo H. X. Shiroma" Date: Mon, 18 Mar 2024 09:55:05 -0700 Subject: [PATCH 2/3] add dot before extension --- src/rtc/rtc_s1.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/rtc/rtc_s1.py b/src/rtc/rtc_s1.py index e62caec..d710b8c 100755 --- a/src/rtc/rtc_s1.py +++ b/src/rtc/rtc_s1.py @@ -603,7 +603,8 @@ def run_parallel(cfg: RunConfig, logfile_path, flag_logger_full_format): # products to avoid sending half-empty products to the DAAC # Do not delete log files for ext in ['h5', 'tif', 'png']: - for f in glob.glob(os.path.join(output_dir_bursts, f'*{ext}')): + for f in glob.glob(os.path.join(output_dir_bursts, + f'*.{ext}')): os.remove(f) # if output burst directory is empty, delete it From 519a7f0fb7ca2ddf0e0e2a5fb69951321b479973 Mon Sep 17 00:00:00 2001 From: "Gustavo H. X. Shiroma" Date: Mon, 18 Mar 2024 09:58:35 -0700 Subject: [PATCH 3/3] add messages to the user in case of error --- src/rtc/rtc_s1.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/rtc/rtc_s1.py b/src/rtc/rtc_s1.py index d710b8c..3a045b9 100755 --- a/src/rtc/rtc_s1.py +++ b/src/rtc/rtc_s1.py @@ -610,6 +610,7 @@ def run_parallel(cfg: RunConfig, logfile_path, flag_logger_full_format): # if output burst directory is empty, delete it if (os.path.isdir(output_dir_bursts) and len(os.listdir(output_dir_bursts)) == 0): + logger.info(f'Removing burst directory: {output_dir_bursts}') os.rmdir(output_dir_bursts) if processing_result == 0: @@ -622,6 +623,7 @@ def run_parallel(cfg: RunConfig, logfile_path, flag_logger_full_format): # if output directory is empty, delete it if (os.path.isdir(output_dir) and len(os.listdir(output_dir)) == 0): + logger.info(f'Removing output directory: {output_dir}') os.rmdir(output_dir) raise RuntimeError(msg_failed_child_proc)