Commit 98d3d3b8 authored by Floreal Cabanettes's avatar Floreal Cabanettes
Browse files

Prevent timeout for summary, Fixes #111

parent 3c620a1a
......@@ -478,16 +478,12 @@ class Paf:
contigs_list.remove(c_name)
return "\n".join(contigs_list) + "\n"
def get_summary_stats(self):
def build_summary_stats(self, status_file):
"""
Get summary of identity
:return: table with percents by category
"""
summary_file = self.paf + ".summary"
if os.path.exists(summary_file):
with open(summary_file, "r") as summary_file:
txt = summary_file.read()
return json.loads(txt)
self.parse_paf(False, False)
if self.parsed:
percents = {}
......@@ -509,5 +505,15 @@ class Paf:
with open(summary_file, "w") as summary_file:
summary_file.write(json.dumps(percents))
os.remove(status_file)
return percents
shutil.move(status_file, status_file + ".fail")
return None
def get_summary_stats(self):
summary_file = self.paf + ".summary"
if os.path.exists(summary_file):
with open(summary_file, "r") as summary_file:
txt = summary_file.read()
return json.loads(txt)
return None
......@@ -19,7 +19,12 @@ dgenies.result.controls.summary = function () {
function (data) {
dgenies.hide_loading();
if (data["success"]) {
dgenies.result.summary.show(data["percents"]);
if (data["status"] === "done") {
dgenies.result.summary.show(data["percents"]);
}
else if (data["status"] === "waiting") {
dgenies.result.controls.summary();
}
}
else {
dgenies.notify(data["message"] || "An error occurred! Please contact us to report the bug", "danger");
......
......@@ -405,15 +405,44 @@ def summary(id_res):
"success": False,
"message": "Unable to load data!"
})
percents = paf.get_summary_stats()
if percents is None:
percents = None
s_status = "waiting" # Accepted values: waiting, done, fail
status_file = os.path.join(APP_DATA, id_res, ".summarize")
fail_file = status_file + ".fail"
if not os.path.exists(status_file): # The job is finished or not started
if not os.path.exists(fail_file): # The job has not started yet or has successfully ended
percents = paf.get_summary_stats()
if percents is None: # The job has not started yet
Path(status_file).touch()
thread = threading.Timer(0, paf.build_summary_stats, kwargs={"status_file": status_file})
thread.start()
else: # The job has successfully ended
s_status = "done"
else: # The job has failed
s_status = "fail"
if s_status == "waiting": # The job is running
# Check if the job end in the next 30 seconds
nb_iter = 0
while os.path.exists(status_file) and not os.path.exists(fail_file) and nb_iter < 10:
time.sleep(3)
nb_iter += 1
if not os.path.exists(status_file): # The job has ended
percents = paf.get_summary_stats()
if percents is None: # The job has failed
s_status = "fail"
else: # The job has successfully ended
s_status = "done"
if s_status == "fail":
return jsonify({
"success": False,
"message": "Build of summary failed. Please contact us to report the bug"
})
return jsonify({
"success": True,
"percents": percents
"percents": percents,
"status": s_status
})
......
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