Skip to content

Commit

Permalink
Avoid reset status to FINISHED when calling getstatus_scan
Browse files Browse the repository at this point in the history
If all threads are finished, change state to FINISHED only if current state is SCANNING to preserve state set to ERROR.
  • Loading branch information
[email protected] committed Jun 18, 2020
1 parent d8ff0e4 commit d2fdc1e
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions PatrowlEnginesUtils/PatrowlEngine.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
Expand Down

0 comments on commit d2fdc1e

Please sign in to comment.