From 3453a169e1d07684063df4db8d224305f9e1ee6b Mon Sep 17 00:00:00 2001 From: jebus Date: Tue, 9 Sep 2025 20:39:26 +1200 Subject: [PATCH] [Feature] Async Prediction Status Poll (#93) Fixed #81 Co-authored-by: Tim Lorsbach Reviewed-on: https://git.envipath.com/enviPath/enviPy/pulls/93 --- epdb/models.py | 12 ++++--- epdb/views.py | 6 ++++ templates/objects/pathway.html | 58 +++++++++++++++++++++++++++++++--- 3 files changed, 68 insertions(+), 8 deletions(-) diff --git a/epdb/models.py b/epdb/models.py index e82e05af..c5002211 100644 --- a/epdb/models.py +++ b/epdb/models.py @@ -1358,14 +1358,17 @@ class Pathway(EnviPathModel, AliasMixin, ScenarioMixin): return self.kv.get('mode', 'build') == 'predicted' # Status + def status(self): + return self.kv.get('status', 'completed') + def completed(self): - return self.kv.get('status', 'completed') == 'completed' + return self.status() == 'completed' def running(self): - return self.kv.get('status', 'completed') == 'running' + return self.status() == 'running' def failed(self): - return self.kv.get('status', 'completed') == 'failed' + return self.status() == 'failed' def d3_json(self): # Ideally it would be something like this but @@ -1472,7 +1475,8 @@ class Pathway(EnviPathModel, AliasMixin, ScenarioMixin): "upToDate": True, "links": adjusted_links, "nodes": nodes, - "modified": self.modified.strftime('%Y-%m-%d %H:%M:%S') + "modified": self.modified.strftime('%Y-%m-%d %H:%M:%S'), + "status": self.status(), } return json.dumps(res) diff --git a/epdb/views.py b/epdb/views.py index 2ce006d2..d5b24c98 100644 --- a/epdb/views.py +++ b/epdb/views.py @@ -1438,6 +1438,12 @@ def package_pathway(request, package_uuid, pathway_uuid): if request.GET.get("last_modified", False): return JsonResponse({'modified': current_pathway.modified.strftime('%Y-%m-%d %H:%M:%S')}) + if request.GET.get('status', False): + return JsonResponse({ + 'status': current_pathway.status(), + 'modified': current_pathway.modified.strftime('%Y-%m-%d %H:%M:%S'), + }) + if request.GET.get("download", False) == "true": filename = f"{current_pathway.name.replace(' ', '_')}_{current_pathway.uuid}.csv" csv_pw = current_pathway.to_csv() diff --git a/templates/objects/pathway.html b/templates/objects/pathway.html index bd1e3880..555bf324 100644 --- a/templates/objects/pathway.html +++ b/templates/objects/pathway.html @@ -149,19 +149,19 @@
  • {% if pathway.completed %} - {% elif pathway.failed %} - {% else %} -