[Feature] Async Prediction Status Poll (#93)

Fixed #81

Co-authored-by: Tim Lorsbach <tim@lorsba.ch>
Reviewed-on: enviPath/enviPy#93
This commit is contained in:
2025-09-09 20:39:26 +12:00
parent 5477b5b3d4
commit 3453a169e1
3 changed files with 68 additions and 8 deletions

View File

@ -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)

View File

@ -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()