From d2fdc1e4aaa736d881b7d8f7933e9a781c48532d Mon Sep 17 00:00:00 2001 From: "contact@grandville.net" Date: Thu, 18 Jun 2020 13:59:59 +0200 Subject: [PATCH] Avoid reset status to FINISHED when calling getstatus_scan If all threads are finished, change state to FINISHED only if current state is SCANNING to preserve state set to ERROR. --- PatrowlEnginesUtils/PatrowlEngine.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/PatrowlEnginesUtils/PatrowlEngine.py b/PatrowlEnginesUtils/PatrowlEngine.py index 87b60cb..9ea75d6 100644 --- a/PatrowlEnginesUtils/PatrowlEngine.py +++ b/PatrowlEnginesUtils/PatrowlEngine.py @@ -179,21 +179,26 @@ def getstatus_scan(self, scan_id): if scan_id not in self.scans.keys(): raise PatrowlEngineExceptions(1002,"scan_id '{}' not found".format(scan_id)) - all_threads_finished = False + all_threads_finished = True for t in self.scans[scan_id]['threads']: if t.isAlive(): - self.scans[scan_id]['status'] = "SCANNING" all_threads_finished = False break - else: - all_threads_finished = True + if all_threads_finished and len(self.scans[scan_id]['threads']) >= 1: - self.scans[scan_id]['status'] = "FINISHED" - self.scans[scan_id]['finished_at'] = int(time.time() * 1000) + + if self.scans[scan_id]['status'] == "SCANNING": + # all threads are finished, ensure scan status is no more SCANNING + self.scans[scan_id]['status'] = "FINISHED" + + if not 'finished_at' in self.scans[scan_id].keys(): + # update finished time if not already set + self.scans[scan_id]['finished_at'] = int(time.time() * 1000) return jsonify({"status": self.scans[scan_id]['status']}) + def getstatus(self): """Get the status of the engine and all its scans.""" res = {"page": "status"}