Skip to content

manager

dev_tool.event.app.manager

AppEventManager

A manager class for application lifecycle events.

This class handles the registration and emission of application events through an event bus system with lifecycle hooks.

The constructor for the AppEventManager class.

Parameters:

  • event_bus (EventBus) –

    The event bus instance for publishing events.

Source code in dev_tool/event/app/manager.py
def __init__(self, event_bus: EventBus) -> None:
    """
    The constructor for the AppEventManager class.

    :param event_bus: The event bus instance for publishing events.
    """

    self._notification_handler: NotificationEventHandler | None = None

    self.config_handler = ConfigEventHandler()
    self.event_bus = event_bus
    self.file_handler = FileEventHandler()
    self.handler = AppLifecycleHandler()
    self.task_handler = TaskEventHandler()

    for event_type in cast('Iterable[AppEventType]', AppEventType):
        self.event_bus.subscribe(event_type, self.handler)

    self._register_domain_handlers()

config_handler = ConfigEventHandler() instance-attribute

event_bus = event_bus instance-attribute

file_handler = FileEventHandler() instance-attribute

handler = AppLifecycleHandler() instance-attribute

task_handler = TaskEventHandler() instance-attribute

emit

A method that emits an application event.

Parameters:

  • event_type (AppEventType) –

    The type of event to emit.

  • data (dict[str, Any] | None, default: None ) –

    Optional event data dictionary.

  • source (str, default: 'app' ) –

    The source of the event.

Source code in dev_tool/event/app/manager.py
def emit(self, event_type: AppEventType, data: dict[str, Any] | None = None, source: str = 'app') -> None:
    """
    A method that emits an application event.

    :param event_type: The type of event to emit.
    :param data: Optional event data dictionary.
    :param source: The source of the event.
    """

    self.event_bus.emit(event_type, data or {}, source=source)

emit_app_event

A method that emits an application lifecycle event.

Parameters:

  • event_type (AppEventType) –

    The type of application event to emit.

  • data (dict[str, Any] | None, default: None ) –

    Optional event data dictionary.

Source code in dev_tool/event/app/manager.py
def emit_app_event(self, event_type: AppEventType, data: dict[str, Any] | None = None) -> None:
    """
    A method that emits an application lifecycle event.

    :param event_type: The type of application event to emit.
    :param data: Optional event data dictionary.
    """

    self.event_bus.emit(event_type, data or {}, source='app')

initialize_notification_handler

A method that initializes the notification handler.

Parameters:

Source code in dev_tool/event/app/manager.py
def initialize_notification_handler(self, notification_service: NotificationService) -> None:
    """
    A method that initializes the notification handler.

    :param notification_service: The notification service instance.
    """

    self._notification_handler = NotificationEventHandler(notification_service)

    for event_type in NotificationEventHandler.get_event_type():
        self.event_bus.subscribe(event_type, self._notification_handler)

register_config_callback

A method that registers a callback for configuration events.

Parameters:

  • event_type (AppEventType) –

    The configuration event type to listen for.

  • callback (Callable[[], None]) –

    The callback function to execute.

Source code in dev_tool/event/app/manager.py
def register_config_callback(self, event_type: AppEventType, callback: Callable[[], None]) -> None:
    """
    A method that registers a callback for configuration events.

    :param event_type: The configuration event type to listen for.
    :param callback: The callback function to execute.
    """

    self.config_handler.register_callback(event_type, callback)

register_file_callback

A method that registers a callback for file events.

Parameters:

  • path (Path) –

    The file path to watch.

  • callback (Callable[[Path], None]) –

    The callback function to execute.

Source code in dev_tool/event/app/manager.py
def register_file_callback(self, path: Path, callback: Callable[[Path], None]) -> None:
    """
    A method that registers a callback for file events.

    :param path: The file path to watch.
    :param callback: The callback function to execute.
    """

    self.file_handler.register_callback(path, callback)

register_hook

A method that registers a function to run when an application event occurs.

Parameters:

  • event_type (AppEventType) –

    The application event type to listen for.

  • function (Callable) –

    The callback function to execute when the event occurs.

Source code in dev_tool/event/app/manager.py
def register_hook(self, event_type: AppEventType, function: Callable) -> None:
    """
    A method that registers a function to run when an application event occurs.

    :param event_type: The application event type to listen for.
    :param function: The callback function to execute when the event occurs.
    """

    self.handler.register_hook(event_type, function)

register_task_watcher

A method that registers a watcher for task events.

Parameters:

  • watcher (Callable[[dict], None]) –

    The watcher function to register.

Source code in dev_tool/event/app/manager.py
def register_task_watcher(self, watcher: Callable[[dict], None]) -> None:
    """
    A method that registers a watcher for task events.

    :param watcher: The watcher function to register.
    """

    self.task_handler.register_watcher(watcher)

unregister_config_callback

A method that unregisters a callback for configuration events.

Parameters:

  • event_type (AppEventType) –

    The configuration event type.

  • callback (Callable[[], None]) –

    The callback function to remove.

Source code in dev_tool/event/app/manager.py
def unregister_config_callback(self, event_type: AppEventType, callback: Callable[[], None]) -> None:
    """
    A method that unregisters a callback for configuration events.

    :param event_type: The configuration event type.
    :param callback: The callback function to remove.
    """

    self.config_handler.unregister_callback(event_type, callback)

unregister_file_callback

A method that unregisters a callback for file events.

Parameters:

  • path (Path) –

    The file path.

  • callback (Callable[[Path], None] | None, default: None ) –

    The callback function to remove, or None to remove all.

Source code in dev_tool/event/app/manager.py
def unregister_file_callback(self, path: Path, callback: Callable[[Path], None] | None = None) -> None:
    """
    A method that unregisters a callback for file events.

    :param path: The file path.
    :param callback: The callback function to remove, or None to remove all.
    """

    self.file_handler.unregister_callback(path, callback)

unregister_task_watcher

A method that unregisters a watcher for task events.

Parameters:

  • watcher (Callable[[dict], None]) –

    The watcher function to unregister.

Source code in dev_tool/event/app/manager.py
def unregister_task_watcher(self, watcher: Callable[[dict], None]) -> None:
    """
    A method that unregisters a watcher for task events.

    :param watcher: The watcher function to unregister.
    """

    self.task_handler.unregister_watcher(watcher)