Skip to content

Commit

Permalink
bug/#2152 on submission change called twice with same status (#2353)
Browse files Browse the repository at this point in the history
resolves #2152

Co-authored-by: Fred Lefévère-Laoide <[email protected]>
  • Loading branch information
FredLL-Avaiga and Fred Lefévère-Laoide authored Dec 18, 2024
1 parent 242894c commit d353533
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 41 deletions.
2 changes: 1 addition & 1 deletion taipy/gui/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -1557,7 +1557,7 @@ def _set_module_context(self, module_context: t.Optional[str]) -> t.ContextManag
def invoke_callback(
self,
state_id: str,
callback: t.Callable,
callback: t.Union[t.Callable, str],
args: t.Optional[t.Sequence[t.Any]] = None,
module_context: t.Optional[str] = None,
) -> t.Any:
Expand Down
81 changes: 41 additions & 40 deletions taipy/gui_core/_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,55 +158,26 @@ def submission_status_callback(self, submission_id: t.Optional[str] = None, even
if not submission_id or not is_readable(t.cast(SubmissionId, submission_id)):
return
submission = None
new_status = None
new_status: t.Optional[SubmissionStatus] = None
payload: t.Optional[t.Dict[str, t.Any]] = None
client_id: t.Optional[str] = None
submission_name: t.Optional[str] = None
try:
last_client_status = self.client_submission.get(submission_id)
if not last_client_status:
return

submission = t.cast(Submission, core_get(submission_id))
if not submission or not submission.entity_id:
return
new_status = submission.submission_status

payload = {}
new_status = t.cast(SubmissionStatus, submission.submission_status)
with self.submissions_lock:
last_client_status = self.client_submission.get(submission_id)
if not last_client_status:
return

client_id = submission.properties.get("client_id")
if client_id:
running_tasks = {}
with self.gui._get_authorization(client_id):
for job in submission.jobs:
job = job if isinstance(job, Job) else t.cast(Job, core_get(job))
running_tasks[job.task.id] = (
SubmissionStatus.RUNNING.value
if job.is_running()
else SubmissionStatus.PENDING.value
if job.is_pending()
else None
)
payload.update(tasks=running_tasks)

if last_client_status.submission_status is not new_status:
# callback
submission_name = submission.properties.get("on_submission")
if submission_name:
self.gui.invoke_callback(
client_id,
submission_name,
[
core_get(submission.id),
{
"submission_status": new_status.name,
"submittable_entity": core_get(submission.entity_id),
**(event.metadata if event else {}),
},
],
submission.properties.get("module_context"),
)
payload = {}
if last_client_status.submission_status is not new_status:
# callback
submission_name = submission.properties.get("on_submission")

with self.submissions_lock:
if new_status in (
SubmissionStatus.COMPLETED,
SubmissionStatus.FAILED,
Expand All @@ -216,6 +187,36 @@ def submission_status_callback(self, submission_id: t.Optional[str] = None, even
else:
last_client_status.submission_status = new_status

if client_id:= submission.properties.get("client_id"):
with self.gui._get_authorization(client_id):
if payload is not None:
running_tasks = {}
for job in submission.jobs:
job = job if isinstance(job, Job) else t.cast(Job, core_get(job))
running_tasks[job.task.id] = (
SubmissionStatus.RUNNING.value
if job.is_running()
else SubmissionStatus.PENDING.value
if job.is_pending()
else None
)
payload.update(tasks=running_tasks)

if submission_name:
self.gui.invoke_callback(
client_id,
submission_name,
[
core_get(submission.id),
{
"submission_status": new_status.name if new_status else "None",
"submittable_entity": core_get(submission.entity_id),
**(event.metadata if event else {}),
},
],
submission.properties.get("module_context"),
)

except Exception as e:
_warn(f"Submission ({submission_id}) is not available", e)

Expand Down

0 comments on commit d353533

Please sign in to comment.