diff --git a/pandora_server/extras/pandoraPlugintools/transfer.py b/pandora_server/extras/pandoraPlugintools/transfer.py index 5b1b67ef11..c607ca8d79 100644 --- a/pandora_server/extras/pandoraPlugintools/transfer.py +++ b/pandora_server/extras/pandoraPlugintools/transfer.py @@ -17,7 +17,8 @@ _GLOBAL_VARIABLES = { 'tentacle_client' : 'tentacle_client', 'tentacle_ip' : '127.0.0.1', 'tentacle_port' : 41121, - 'tentacle_extra_opts' : '' + 'tentacle_extra_opts' : '', + 'tentacle_retries' : 1 } #### @@ -79,6 +80,7 @@ def tentacle_xml( data_file: str = "", tentacle_ops: dict = {}, tentacle_path: str = _GLOBAL_VARIABLES['tentacle_client'], + retry: bool = False, debug: int = 0, print_errors: bool = True ) -> bool: @@ -89,6 +91,7 @@ def tentacle_xml( data_file (str): Path to the data file to be sent. tentacle_ops (dict): Tentacle options as a dictionary (address [password] [port]). tentacle_path (str): Custom path for the tentacle client executable. + retry (bool): Whether to retry sending the file if it fails. debug (int): Debug mode flag. If enabled (1), the data file will not be removed after sending. print_errors (bool): Whether to print error messages. @@ -122,18 +125,49 @@ def tentacle_xml( tentacle_cmd = f"{tentacle_path} -v -a {tentacle_ops['address']} -p {tentacle_ops['port']} {tentacle_ops['extra_opts']} {data_file.strip()}" - tentacle_exe=subprocess.Popen(tentacle_cmd, stdout=subprocess.PIPE,stderr=subprocess.PIPE, shell=True) - rc=tentacle_exe.wait() - - if debug == 0 : - os.remove(data_file.strip()) + if retry: - if rc != 0 : - if print_errors: - stderr = tentacle_exe.stderr.read().decode() - msg="Tentacle error:" + str(stderr) - print_stderr(str(datetime.today().strftime('%Y-%m-%d %H:%M')) + msg) - return False + retry_count = 0 + + while retry_count < _GLOBAL_VARIABLES['tentacle_retries'] : + + tentacle_exe=subprocess.Popen(tentacle_cmd, stdout=subprocess.PIPE,stderr=subprocess.PIPE, shell=True) + rc=tentacle_exe.wait() + + if debug == 0 : + os.remove(data_file.strip()) + + if rc == 0: + break + + if print_errors: + stderr = tentacle_exe.stderr.read().decode() + msg = f"Tentacle error (Retry {retry_count + 1}/{_GLOBAL_VARIABLES['tentacle_retries']}): {stderr}" + print_stderr(str(datetime.today().strftime('%Y-%m-%d %H:%M')) + msg) + + retry_count += 1 + + if retry_count >= _GLOBAL_VARIABLES['tentacle_retries']: + if print_errors: + stderr = tentacle_exe.stderr.read().decode() + msg = f"Tentacle error (Final Retry): {stderr}" + print_stderr(str(datetime.today().strftime('%Y-%m-%d %H:%M')) + msg) + return False + + else: + + tentacle_exe=subprocess.Popen(tentacle_cmd, stdout=subprocess.PIPE,stderr=subprocess.PIPE, shell=True) + rc=tentacle_exe.wait() + + if debug == 0 : + os.remove(data_file.strip()) + + if rc != 0 : + if print_errors: + stderr = tentacle_exe.stderr.read().decode() + msg="Tentacle error:" + str(stderr) + print_stderr(str(datetime.today().strftime('%Y-%m-%d %H:%M')) + msg) + return False else: if print_errors: