Skip to content

Commit

Permalink
Submission status update
Browse files Browse the repository at this point in the history
resolves #1419
  • Loading branch information
Fred Lefévère-Laoide authored and Fred Lefévère-Laoide committed Jun 19, 2024
1 parent f49b148 commit 6828e41
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 54 deletions.
9 changes: 4 additions & 5 deletions frontend/taipy/src/ScenarioViewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,6 @@ const ScenarioViewer = (props: ScenarioViewerProps) => {
}
}
setValid(!!sc);
// setSubmissionStatus(0);
setScenario((oldSc) => (oldSc === sc ? oldSc : sc ? (deepEqual(oldSc, sc) ? oldSc : sc) : invalidScenario));
}, [props.scenario, props.defaultScenario]);

Expand Down Expand Up @@ -579,7 +578,7 @@ const ScenarioViewer = (props: ScenarioViewerProps) => {
const addSequenceHandler = useCallback(() => setSequences((seq) => [...seq, ["", [], "", true]]), []);

// Submission status
const [submissionStatus, setSubmissionStatus] = useState(0);
const [submissionStatus, setSubmissionStatus] = useState(-1);

// on scenario change
useEffect(() => {
Expand All @@ -594,10 +593,10 @@ const ScenarioViewer = (props: ScenarioViewerProps) => {
useEffect(() => {
const ids = props.coreChanged?.scenario;
if (typeof ids === "string" ? ids === scId : Array.isArray(ids) ? ids.includes(scId) : ids) {
props.updateVarName && dispatch(createRequestUpdateAction(id, module, [props.updateVarName], true));
if (props.coreChanged?.submission !== undefined) {
if (typeof props.coreChanged?.submission === "number") {
setSubmissionStatus(props.coreChanged?.submission as number);
}
props.updateVarName && dispatch(createRequestUpdateAction(id, module, [props.updateVarName], true));
}
}, [props.coreChanged, props.updateVarName, id, module, dispatch, scId]);

Expand Down Expand Up @@ -629,7 +628,7 @@ const ScenarioViewer = (props: ScenarioViewerProps) => {
sx={ChipSx}
/>
) : null}
{submissionStatus ? <StatusChip status={submissionStatus} sx={ChipSx} /> : null}
{submissionStatus > -1 ? <StatusChip status={submissionStatus} sx={ChipSx} /> : null}
</Grid>
<Grid item>
{showSubmit ? (
Expand Down
3 changes: 2 additions & 1 deletion frontend/taipy/src/StatusChip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { SxProps, Theme } from "@mui/material";
import Chip from "@mui/material/Chip";

export enum Status {
SUBMITTED = 1,
SUBMITTED = 0,
UNDEFINED = 1,
BLOCKED = 2,
PENDING = 3,
RUNNING = 4,
Expand Down
1 change: 1 addition & 0 deletions taipy/gui/_renderers/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -946,6 +946,7 @@ def set_attributes(self, attributes: t.List[tuple]): # noqa: C901
attributes (list(tuple)): The list of attributes as (property name, property type, default value).
"""
attributes.append(("id",)) # Every element should have an id attribute
for attr in attributes:
if not isinstance(attr, tuple):
attr = (attr,)
Expand Down
27 changes: 0 additions & 27 deletions taipy/gui/_renderers/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ class _Factory:
.set_value_and_default(with_update=False)
.set_attributes(
[
("id",),
("on_action", PropertyType.function),
("active", PropertyType.dynamic_boolean, True),
("hover_text", PropertyType.dynamic_string),
Expand All @@ -90,7 +89,6 @@ class _Factory:
.set_value_and_default(with_update=True, with_default=False, var_type=PropertyType.data)
.set_attributes(
[
("id",),
("on_action", PropertyType.function),
("active", PropertyType.dynamic_boolean, True),
("hover_text", PropertyType.dynamic_string),
Expand All @@ -107,7 +105,6 @@ class _Factory:
.set_value_and_default(with_default=False, var_type=PropertyType.data)
.set_attributes(
[
("id",),
("title",),
("width", PropertyType.string_or_number),
("height", PropertyType.string_or_number),
Expand Down Expand Up @@ -140,7 +137,6 @@ class _Factory:
.set_attributes(
[
("with_time", PropertyType.boolean),
("id",),
("active", PropertyType.dynamic_boolean, True),
("editable", PropertyType.dynamic_boolean, True),
("hover_text", PropertyType.dynamic_string),
Expand All @@ -160,7 +156,6 @@ class _Factory:
.set_attributes(
[
("with_time", PropertyType.boolean),
("id",),
("active", PropertyType.dynamic_boolean, True),
("editable", PropertyType.dynamic_boolean, True),
("hover_text", PropertyType.dynamic_string),
Expand All @@ -181,7 +176,6 @@ class _Factory:
._set_partial() # partial should be set before page
.set_attributes(
[
("id",),
("page",),
("title",),
("on_action", PropertyType.function),
Expand All @@ -201,7 +195,6 @@ class _Factory:
._set_partial() # partial should be set before page
.set_attributes(
[
("id",),
("page",),
("expanded", PropertyType.dynamic_boolean, True, True, False),
("hover_text", PropertyType.dynamic_string),
Expand All @@ -218,7 +211,6 @@ class _Factory:
._set_content("content", image=False)
.set_attributes(
[
("id",),
("on_action", PropertyType.function),
("active", PropertyType.dynamic_boolean, True),
("render", PropertyType.dynamic_boolean, True),
Expand All @@ -238,7 +230,6 @@ class _Factory:
._set_file_content()
.set_attributes(
[
("id",),
("on_action", PropertyType.function),
("active", PropertyType.dynamic_boolean, True),
("multiple", PropertyType.boolean, False),
Expand All @@ -258,7 +249,6 @@ class _Factory:
._set_content("content")
.set_attributes(
[
("id",),
("on_action", PropertyType.function),
("active", PropertyType.dynamic_boolean, True),
("width",),
Expand All @@ -275,7 +265,6 @@ class _Factory:
.set_value_and_default(with_update=False, native_type=True)
.set_attributes(
[
("id",),
("min", PropertyType.number),
("max", PropertyType.number),
("value", PropertyType.dynamic_number),
Expand All @@ -296,7 +285,6 @@ class _Factory:
._set_propagate()
.set_attributes(
[
("id",),
("active", PropertyType.dynamic_boolean, True),
("hover_text", PropertyType.dynamic_string),
("on_change", PropertyType.function),
Expand All @@ -314,7 +302,6 @@ class _Factory:
.set_value_and_default(with_default=False)
.set_attributes(
[
("id",),
("columns[mobile]",),
("gap",),
]
Expand All @@ -325,7 +312,6 @@ class _Factory:
.set_value_and_default(default_val="Log-in")
.set_attributes(
[
("id",),
("message", PropertyType.dynamic_string),
("on_action", PropertyType.function, "on_login"),
]
Expand All @@ -338,7 +324,6 @@ class _Factory:
)
.set_attributes(
[
("id",),
("active", PropertyType.dynamic_boolean, True),
("label",),
("width",),
Expand All @@ -359,7 +344,6 @@ class _Factory:
.set_value_and_default(var_type=PropertyType.dynamic_number, native_type=True)
.set_attributes(
[
("id",),
("title",),
("active", PropertyType.dynamic_boolean, True),
("layout", PropertyType.dynamic_dict),
Expand All @@ -383,7 +367,6 @@ class _Factory:
gui=gui, control_type=control_type, element_name="NavBar", attributes=attrs, default_value=None
).set_attributes(
[
("id",),
("active", PropertyType.dynamic_boolean, True),
("hover_text", PropertyType.dynamic_string),
("lov", PropertyType.single_lov),
Expand All @@ -401,7 +384,6 @@ class _Factory:
._set_propagate()
.set_attributes(
[
("id",),
("active", PropertyType.dynamic_boolean, True),
("hover_text", PropertyType.dynamic_string),
("on_change", PropertyType.function),
Expand All @@ -417,7 +399,6 @@ class _Factory:
._set_partial() # partial should be set before page
.set_attributes(
[
("id",),
("page",),
("anchor", PropertyType.string, "left"),
("on_close", PropertyType.function),
Expand All @@ -436,7 +417,6 @@ class _Factory:
._set_partial() # partial should be set before page
.set_attributes(
[
("id",),
("page", PropertyType.dynamic_string),
("render", PropertyType.dynamic_boolean, True),
("height", PropertyType.dynamic_string),
Expand All @@ -454,7 +434,6 @@ class _Factory:
("filter", PropertyType.boolean),
("height", PropertyType.string_or_number),
("hover_text", PropertyType.dynamic_string),
("id",),
("value_by_id", PropertyType.boolean),
("multiple", PropertyType.boolean),
("width", PropertyType.string_or_number),
Expand All @@ -478,7 +457,6 @@ class _Factory:
("active", PropertyType.dynamic_boolean, True),
("height",),
("hover_text", PropertyType.dynamic_string),
("id",),
("value_by_id", PropertyType.boolean),
("max", PropertyType.number, 100),
("min", PropertyType.number, 0),
Expand All @@ -503,7 +481,6 @@ class _Factory:
.set_value_and_default(with_update=False)
.set_attributes(
[
("id",),
("without_close", PropertyType.boolean, False),
("hover_text", PropertyType.dynamic_string),
]
Expand All @@ -524,7 +501,6 @@ class _Factory:
("auto_loading", PropertyType.boolean),
("width", PropertyType.string_or_number, "100%"),
("height", PropertyType.string_or_number, "80vh"),
("id",),
("active", PropertyType.dynamic_boolean, True),
("editable", PropertyType.dynamic_boolean, True),
("on_edit", PropertyType.function),
Expand Down Expand Up @@ -552,7 +528,6 @@ class _Factory:
.set_attributes(
[
("format",),
("id",),
("hover_text", PropertyType.dynamic_string),
("raw", PropertyType.boolean, False),
("mode",),
Expand All @@ -566,7 +541,6 @@ class _Factory:
[
("active", PropertyType.dynamic_boolean, True),
("hover_text", PropertyType.dynamic_string),
("id",),
("label",),
("value_by_id", PropertyType.boolean),
("unselected_value", PropertyType.string, ""),
Expand All @@ -592,7 +566,6 @@ class _Factory:
("filter", PropertyType.boolean),
("hover_text", PropertyType.dynamic_string),
("height", PropertyType.string_or_number),
("id",),
("value_by_id", PropertyType.boolean),
("multiple", PropertyType.boolean),
("width", PropertyType.string_or_number),
Expand Down
40 changes: 19 additions & 21 deletions taipy/gui_core/_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,7 @@ def process_event(self, event: Event):
else None
)
if sequence and hasattr(sequence, "parent_ids") and sequence.parent_ids: # type: ignore
self.gui._broadcast(
_GuiCoreContext._CORE_CHANGED_NAME,
{"scenario": list(sequence.parent_ids)}, # type: ignore
)
self.broadcast_core_changed({"scenario": list(sequence.parent_ids)})
except Exception as e:
_warn(f"Access to sequence {event.entity_id} failed", e)
elif event.entity_type == EventEntityType.JOB:
Expand All @@ -133,25 +130,26 @@ def process_event(self, event: Event):
elif event.entity_type == EventEntityType.DATA_NODE:
with self.lock:
self.data_nodes_by_owner = None
self.gui._broadcast(
_GuiCoreContext._CORE_CHANGED_NAME,
{"datanode": event.entity_id if event.operation != EventOperation.DELETION else True},
self.broadcast_core_changed(
{"datanode": event.entity_id if event.operation != EventOperation.DELETION else True}
)

def broadcast_core_changed(self, payload: t.Dict[str, t.Any], client_id: t.Optional[str] = None):
self.gui._broadcast(_GuiCoreContext._CORE_CHANGED_NAME, payload, client_id)

def scenario_refresh(self, scenario_id: t.Optional[str]):
with self.lock:
self.scenario_by_cycle = None
self.data_nodes_by_owner = None
self.gui._broadcast(
_GuiCoreContext._CORE_CHANGED_NAME,
{"scenario": scenario_id or True},
)
self.broadcast_core_changed({"scenario": scenario_id or True})

def submission_status_callback(self, submission_id: t.Optional[str] = None, event: t.Optional[Event] = None):
if not submission_id or not is_readable(t.cast(SubmissionId, submission_id)):
return
submission = None
new_status = None
payload: t.Optional[t.Dict[str, t.Any]] = None
client_id: t.Optional[str] = None
try:
last_status = self.client_submission.get(submission_id)
if not last_status:
Expand All @@ -161,6 +159,7 @@ def submission_status_callback(self, submission_id: t.Optional[str] = None, even
if not submission or not submission.entity_id:
return

payload = {}
new_status = t.cast(SubmissionStatus, submission.submission_status)

client_id = submission.properties.get("client_id")
Expand All @@ -176,7 +175,7 @@ def submission_status_callback(self, submission_id: t.Optional[str] = None, even
if job.is_pending()
else None
)
self.gui._broadcast(_GuiCoreContext._CORE_CHANGED_NAME, {"tasks": running_tasks}, client_id)
payload.update(tasks=running_tasks)

if last_status != new_status:
# callback
Expand Down Expand Up @@ -210,15 +209,14 @@ def submission_status_callback(self, submission_id: t.Optional[str] = None, even
_warn(f"Submission ({submission_id}) is not available", e)

finally:
entity_id = submission.entity_id if submission else None
self.gui._broadcast(
_GuiCoreContext._CORE_CHANGED_NAME,
{
"jobs": True,
"scenario": entity_id or False,
"submission": new_status.value if new_status else None,
},
)
if payload is not None:
payload.update(jobs=True)
entity_id = submission.entity_id if submission else None
if entity_id:
payload.update(scenario=entity_id)
if new_status:
payload.update(submission=new_status.value)
self.broadcast_core_changed(payload, client_id)

def no_change_adapter(self, entity: t.List):
return entity
Expand Down

0 comments on commit 6828e41

Please sign in to comment.