Repository: Avaiga/taipy
File: taipy/core/notification/core_event_consumer.py (Python)

Code before:
from .event import Event


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.
    It should be subclassed, and the `process_event` method should be implemented to define
    the custom logic for handling incoming events.

    Example usage:

    ```python
    class MyEventConsumer(CoreEventConsumerBase):
        def process_event(self, event: Event):
            # Custom event processing logic here
            print(f"Received event created at : {event.creation_date}")
            pass

    registration_id, registered_queue = Notifier.unregister(
        entity_type=EventEntityType.CYCLE,
        entity_id="CYCLE_cycle_1",
        operation=EventOperation.CREATION
    )

    consumer = MyEventConsumer("consumer_1", registered_queue)
    consumer.start()
    # ...
    consumer.stop()

    Notifier.unregister(registration_id)
    ```

    Subclasses should implement the `process_event` method to define their specific event handling behavior.

    Attributes:
        queue (SimpleQueue): The queue from which events will be consumed.


    """

    def __init__(self, registration_id: str, queue: SimpleQueue) -> None:
        """Initialize a CoreEventConsumerBase instance.

        Parameters:
            registration_id (str): A unique identifier of the registration. You can get a
                registration id invoking `Notifier.register()^` method.
            queue (SimpleQueue): The queue from which events will be consumed. You can get a
                queue invoking `Notifier.register()^` method.
        """
        threading.Thread.__init__(self, name=f"Thread-Taipy-Core-Consumer-{registration_id}")

Review comment (suggestion):
```suggestion
    consumer = MyEventConsumer(registration_id, registered_queue)
```

Code after:
from .event import Event


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.
    It should be subclassed, and the `process_event` method should be implemented to define
    the custom logic for handling incoming events.

    Subclasses should implement the `process_event` method to define their specific event handling behavior.

    Example usage:

    ```python
    class MyEventConsumer(CoreEventConsumerBase):
        def process_event(self, event: Event):
            # Custom event processing logic here
            print(f"Received event created at : {event.creation_date}")
            pass

    registration_id, registered_queue = Notifier.register(
        entity_type=EventEntityType.SCENARIO,
        operation=EventOperation.CREATION
    )

    consumer = MyEventConsumer(registration_id, registered_queue)
    consumer.start()
    # ...
    consumer.stop()

    Notifier.unregister(registration_id)
    ```

    Firstly, we would create a consumer class extending from CoreEventConsumerBase
    and decide how to process the incoming events by defining the process_event.
    Then, we would specify the type of event we want to receive by registering with the Notifier.
    After that, we create an object of the consumer class by providing
    the registration_id and registered_queue and start consuming the event.

    Attributes:
        queue (SimpleQueue): The queue from which events will be consumed.


    """

    def __init__(self, registration_id: str, queue: SimpleQueue) -> None:
        """Initialize a CoreEventConsumerBase instance.

        Parameters:
            registration_id (str): A unique identifier of the registration. You can get a