Commit bf38a4ea authored by renzo's avatar renzo Committed by Renzo Marini

agregada funcion de download and process para pasarle a try_execute

parent d90c792f
......@@ -23,7 +23,9 @@ def try_execute(max_tries, waiting_time, f, args):
return
except Exception as e:
time.sleep(waiting_time)
logging.exception(datetime.now())
print("TIMESTAMP: " + str(datetime.now()))
print("ERROR:")
print(e)
tries += 1
raise RuntimeError
......@@ -76,20 +78,30 @@ def enable_same_calls(handle):
fcntl.flock(handle, fcntl.LOCK_UN)
handle.close()
def download_and_process(source, source_config, downloader_args):
start_logging(args, "download")
source_config["download"](*downloader_args)
start_logging(args, "process")
exec.process(source, args)
def start(args):
# Try to execute downloading and processing scripts
try:
lock_handle = disable_same_calls(args)
source = args["source"]
if not args["only_process"]:
source_config = getattr(metadata, source)
downloader_args = get_downloader_args(source_config["download"], args)
source_config = getattr(metadata, source)
downloader_args = get_downloader_args(source_config["download"], args)
# Normal case, process and download
if not args["only_process"] and not args["only_download"]:
try_execute(source_config["max_tries"], source_config["wait"], download_and_process, [source, source_config, downloader_args])
elif args["only_download"]:
start_logging(args, "download")
try_execute(source_config["max_tries"], source_config["wait"], source_config["download"], downloader_args)
if not args["only_download"]:
elif args["only_process"]:
start_logging(args, "process")
exec.process(source, args)
try_execute(source_config["max_tries"], source_config["wait"], exec.process, [source, args])
except Exception as e:
logging.exception(str(datetime.now()) + "\n" + repr(e))
mail.send(source)
......
......@@ -48,8 +48,9 @@ def process(source, args):
script_path = metadata.matlab_scripts + "/" + script + ".m"
date_formatted = args["date"].strftime("%Y%m%d")
data_dir = metadata.tmp_path + "/" + date_formatted
args["date"] = date_formatted
copy(script_path, data_dir)
os.chdir(data_dir)
matlab_call = create_matlab_call(script, source, args)
subprocess.run(matlab_call, shell=True, check=True, stderr=sys.stderr, stdout=sys.stdout)
\ No newline at end of file
matlab_args = args.copy()
matlab_args["date"] = date_formatted
matlab_call = create_matlab_call(script, source, matlab_args)
subprocess.run(matlab_call, shell=True, check=True, stderr=sys.stderr, stdout=sys.stdout)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment