Skip to content

Event consumer API simplification into develop #2566

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

Open
wants to merge 15 commits into
base: develop
Choose a base branch
from
1 change: 1 addition & 0 deletions taipy/core/common/_check_dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def _check_dependency_is_installed(module_name: str, package_name: str) -> None:
class EnterpriseEditionUtils:
_TAIPY_ENTERPRISE_MODULE = "taipy.enterprise"
_TAIPY_ENTERPRISE_CORE_MODULE = _TAIPY_ENTERPRISE_MODULE + ".core"
_TAIPY_ENTERPRISE_EVENT_PACKAGE = _TAIPY_ENTERPRISE_MODULE + ".event"

@classmethod
def _using_enterprise(cls) -> bool:
Expand Down
1 change: 0 additions & 1 deletion taipy/core/notification/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

from ._registration import _Registration
from ._topic import _Topic
from .core_event_consumer import CoreEventConsumerBase
from .event import Event, EventEntityType, EventOperation, _make_event
from .notifier import Notifier, _publish_event
from .registration_id import RegistrationId
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from .event import Event


class CoreEventConsumerBase(threading.Thread):
class _CoreEventConsumerBase(threading.Thread):
"""Abstract base class for implementing a Core event consumer.

This class provides a framework for consuming events from a queue in a separate thread.
Expand Down
10 changes: 10 additions & 0 deletions taipy/event/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Copyright 2021-2025 Avaiga Private Limited
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
# an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
# specific language governing permissions and limitations under the License.
25 changes: 25 additions & 0 deletions taipy/event/_event_callback.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Copyright 2021-2025 Avaiga Private Limited
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
# an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
# specific language governing permissions and limitations under the License.
from dataclasses import dataclass, field
from typing import Callable, List, Optional

from taipy.core.notification import Event


@dataclass
class _Callback:
callback: Callable
args: Optional[List] = field(default_factory=list)
broadcast: Optional[bool] = False
filter: Optional[Callable[[Event], bool]] = None

def __hash__(self):
return hash(self.callback)
26 changes: 26 additions & 0 deletions taipy/event/_event_processor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Copyright 2021-2025 Avaiga Private Limited
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
# an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
# specific language governing permissions and limitations under the License.
from taipy.core.notification import Event


class _AbstractEventProcessor:
"""Abstract base class for implementing an event processor."""

@classmethod
def process_event(cls, event_consumer, event: Event):
raise NotImplementedError("Subclasses must implement this method.")

class _EventProcessor(_AbstractEventProcessor):

@classmethod
def process_event(cls, event_consumer, event: Event):
event_consumer._process_event(event)

Loading
Loading