Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify Core Event to make it accessible #2306

Open
1 of 4 tasks
FlorianJacta opened this issue Dec 6, 2024 · 0 comments
Open
1 of 4 tasks

Simplify Core Event to make it accessible #2306

FlorianJacta opened this issue Dec 6, 2024 · 0 comments
Labels
Core Related to Taipy Core 📈 Improvement Improvement of a feature. 🟨 Priority: Medium Not blocking but should be addressed

Comments

@FlorianJacta
Copy link
Member

Description

The code to configure Core Event is challenging for new comers. We should find a way to make it simple:

from taipy.core import Status
from taipy.core.notification import (
    CoreEventConsumerBase,
    EventEntityType,
    EventOperation,
    Notifier,
)
from taipy.auth import Authorize, login
import taipy as tp
from taipy.gui import notify, invoke_callback, Gui
import time
import datetime as dt


def notify_user(state, data_node_id, scenario_id):
    if state.credentials is not None:
        try:
            with Authorize(state.credentials):
                data_node = tp.get(data_node_id)
                print(
                    f"Updating data node {data_node.config_id} in scenario {scenario_id}"
                )

                if state.scenario.id == scenario_id:
                    if data_node.config_id == "mask_layer_trend_combined":
                        state.mask_layer_trend_combined = data_node.read()
                    elif data_node.config_id == "filtered_stock_and_mask_layer_trend":
                        state.filtered_stock_and_mask_layer_trend = data_node.read()

        except Exception as e:
            print(e)


class SpecificCoreConsumer(CoreEventConsumerBase):
    def __init__(self, gui: Gui):
        self.gui = gui

        reg_id, queue = Notifier.register(
            EventEntityType.JOB, operation=EventOperation.UPDATE
        )  # Adapt the registration to the events you want to listen to
        super().__init__(reg_id, queue)

    def process_event(self, event):
        with Authorize(login(ADMIN, ADMIN)):
            if (
                event.entity_type == EventEntityType.JOB
                and event.operation == EventOperation.UPDATE
            ):
                if (
                    event.attribute_name == "status"
                    and event.attribute_value == Status.COMPLETED
                ):
                    task = tp.get(event.entity_id).task
                    outputs = task.output
                    for data_node in outputs.values():
                        try:
                            scenario_id = data_node.owner_id
                            if scenario_id is not None:
                                self.gui.broadcast_callback(
                                    notify_user,
                                    [data_node.id, scenario_id],
                                )
                        except Exception as e:
                            print(e)

I was also not able to code a similar Core Event that is called when a data node is updated.

Acceptance Criteria

  • Any new code is covered by a unit tested.
  • Check code coverage is at least 90%.

Code of Conduct

  • I have checked the existing issues.
  • I am willing to work on this issue (optional)
@FlorianJacta FlorianJacta added Core Related to Taipy Core 📈 Improvement Improvement of a feature. 🟨 Priority: Medium Not blocking but should be addressed labels Dec 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Core Related to Taipy Core 📈 Improvement Improvement of a feature. 🟨 Priority: Medium Not blocking but should be addressed
Projects
None yet
Development

No branches or pull requests

1 participant