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

feature/#416 documentation for core notification #1047

Merged
merged 11 commits into from
Sep 3, 2024

Conversation

toan-quach
Copy link
Member

@jrobinAV jrobinAV added Core Related to Taipy Core 🟧 Priority: High Stalls work on the project or its dependents labels Jul 25, 2024
Copy link
Member

@jrobinAV jrobinAV left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mkdocs.yml_template must be updated as well

docs/manuals/userman/sdm/events/index.md Show resolved Hide resolved
Copy link
Member

@jrobinAV jrobinAV left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just realize the Topic class is private. Instead of talking about topics we should talk about registration through the register method.

Copy link
Member

@jrobinAV jrobinAV left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made a proposal to make a more direct index page

@FlorianJacta
Copy link
Member

So, right now, there are no parts concerning the connection to the GUI?

Copy link

This PR has been labelled as "🥶Waiting for contributor" because it has been inactive for more than 14 days. If you would like to continue working on this PR, then please add new commit or another comment, otherwise this PR will be closed in 14 days. For more information please refer to the contributing guidelines.

@github-actions github-actions bot added the 🥶Waiting for contributor Issues or PRs waiting for a long time label Aug 15, 2024
docs/manuals/userman/sdm/events/events-description.md Outdated Show resolved Hide resolved
docs/manuals/userman/sdm/events/events-description.md Outdated Show resolved Hide resolved
docs/manuals/userman/sdm/events/events-description.md Outdated Show resolved Hide resolved
docs/manuals/userman/sdm/events/events-description.md Outdated Show resolved Hide resolved
docs/manuals/userman/sdm/events/index.md Outdated Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to add a couple of real examples.

docs/manuals/userman/sdm/events/understanding-topics.md Outdated Show resolved Hide resolved
docs/manuals/userman/sdm/events/understanding-topics.md Outdated Show resolved Hide resolved
@jrobinAV
Copy link
Member

I just realize the Topic class is private. Instead of talking about topics we should talk about registration through the register method.

I made a proposal removing the term topic. @toan-quach please tell me what you think.

@github-actions github-actions bot removed the 🥶Waiting for contributor Issues or PRs waiting for a long time label Aug 21, 2024
@jrobinAV jrobinAV mentioned this pull request Aug 22, 2024
2 tasks
@FlorianJacta
Copy link
Member

FlorianJacta commented Aug 22, 2024

Revision of JR example on how to notify the user of a Core event:

import taipy as tp
from taipy import Config, Core, Gui, Scope
from taipy.gui import notify
import taipy.gui.builder as tgb
from taipy.core.notification import (
    Notifier,
    CoreEventConsumerBase,
    EventOperation,
    EventEntityType,
)
from taipy.core import SubmissionStatus


##### Configuration and Functions #####
from taipy import Config


def build_message(name: str):
    return f"Hello {name}!"


name_data_node_cfg = Config.configure_data_node(id="input_name", default_data="Florian")
message_data_node_cfg = Config.configure_data_node(id="message")
build_msg_task_cfg = Config.configure_task(
    "build_msg", build_message, name_data_node_cfg, message_data_node_cfg
)
scenario_cfg = Config.configure_scenario("scenario", task_configs=[build_msg_task_cfg])
#### Listen on Core Events ####


value = "Default text"


class SpecificCoreConsumer(CoreEventConsumerBase):
    def __init__(self, gui):
        self.gui = gui
        reg_id, queue = (
            Notifier.register()
        )  # Adapt the registration to the events you want to listen to
        super().__init__(reg_id, queue)

    def process_event(self, event):
        if event.operation == EventOperation.CREATION:
            if event.entity_type == EventEntityType.SCENARIO:
                self.gui.broadcast_callback(notify_users_of_creation)
        elif event.operation == EventOperation.UPDATE:
            if event.entity_type == EventEntityType.SUBMISSION:
                print(event)
                if event.attribute_value == SubmissionStatus.COMPLETED:
                    scenario_id = event.metadata["origin_entity_id"]
                    scenario = tp.get(scenario_id)
                    new_value_of_dn = scenario.message.read()
                    self.gui.broadcast_callback(
                        notify_users_of_update, [new_value_of_dn]
                    )
        else:
            pass


#### Notification function to be called ####


def notify_users_of_creation(state):
    state.value = "Scenario created and submitted"
    notify(state, "s", "Scenario Created")


def notify_users_of_update(state, new_value_of_dn):
    print("Value of Data Node:", new_value_of_dn)
    state.value = f"Data Node updated with value: {new_value_of_dn}"
    notify(state, "i", "Data Node Updated")


#### Normal callbacks ####


def create_and_submit_scenario(state):
    scenario = tp.create_scenario(config=scenario_cfg)
    tp.submit(scenario)


#### Page ####

with tgb.Page() as page:
    tgb.text("{value}")
    tgb.button("Press me!", on_action=create_and_submit_scenario)


if __name__ == "__main__":
    core = Core()
    gui = Gui(page)
    core.run()
    SpecificCoreConsumer(gui).start()
    gui.run()

[2024-08-22 17:52:03.010][Taipy][INFO] job JOB_build_msg_56045147-372b-4968-85b5-c0a70d38cf6e is completed.

Value of Data Node: Hello Florian

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would add a short description and explanation of the example with some motivation.
It would also be great to add examples showing how to integrate with an external system, like sending an email when a job fails and calling a Rest API when a new cycle is created.

@jrobinAV jrobinAV merged commit 4c2845a into develop Sep 3, 2024
1 check passed
@jrobinAV jrobinAV deleted the feature/#416-core-notification-documentation branch September 3, 2024 06:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Core Related to Taipy Core 🟧 Priority: High Stalls work on the project or its dependents
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants