mirror of
https://github.com/pandorafms/pandorafms.git
synced 2025-07-28 16:24:54 +02:00
added retry option in the tranfer module
This commit is contained in:
parent
3a3bfadedd
commit
98670ea349
@ -17,7 +17,8 @@ _GLOBAL_VARIABLES = {
|
|||||||
'tentacle_client' : 'tentacle_client',
|
'tentacle_client' : 'tentacle_client',
|
||||||
'tentacle_ip' : '127.0.0.1',
|
'tentacle_ip' : '127.0.0.1',
|
||||||
'tentacle_port' : 41121,
|
'tentacle_port' : 41121,
|
||||||
'tentacle_extra_opts' : ''
|
'tentacle_extra_opts' : '',
|
||||||
|
'tentacle_retries' : 1
|
||||||
}
|
}
|
||||||
|
|
||||||
####
|
####
|
||||||
@ -79,6 +80,7 @@ def tentacle_xml(
|
|||||||
data_file: str = "",
|
data_file: str = "",
|
||||||
tentacle_ops: dict = {},
|
tentacle_ops: dict = {},
|
||||||
tentacle_path: str = _GLOBAL_VARIABLES['tentacle_client'],
|
tentacle_path: str = _GLOBAL_VARIABLES['tentacle_client'],
|
||||||
|
retry: bool = False,
|
||||||
debug: int = 0,
|
debug: int = 0,
|
||||||
print_errors: bool = True
|
print_errors: bool = True
|
||||||
) -> bool:
|
) -> bool:
|
||||||
@ -89,6 +91,7 @@ def tentacle_xml(
|
|||||||
data_file (str): Path to the data file to be sent.
|
data_file (str): Path to the data file to be sent.
|
||||||
tentacle_ops (dict): Tentacle options as a dictionary (address [password] [port]).
|
tentacle_ops (dict): Tentacle options as a dictionary (address [password] [port]).
|
||||||
tentacle_path (str): Custom path for the tentacle client executable.
|
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.
|
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.
|
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_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)
|
if retry:
|
||||||
rc=tentacle_exe.wait()
|
|
||||||
|
|
||||||
if debug == 0 :
|
retry_count = 0
|
||||||
os.remove(data_file.strip())
|
|
||||||
|
|
||||||
if rc != 0 :
|
while retry_count < _GLOBAL_VARIABLES['tentacle_retries'] :
|
||||||
if print_errors:
|
|
||||||
stderr = tentacle_exe.stderr.read().decode()
|
tentacle_exe=subprocess.Popen(tentacle_cmd, stdout=subprocess.PIPE,stderr=subprocess.PIPE, shell=True)
|
||||||
msg="Tentacle error:" + str(stderr)
|
rc=tentacle_exe.wait()
|
||||||
print_stderr(str(datetime.today().strftime('%Y-%m-%d %H:%M')) + msg)
|
|
||||||
return False
|
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:
|
else:
|
||||||
if print_errors:
|
if print_errors:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user