Skip to content

castlecraft_engineer.abstractions.event_handler

castlecraft_engineer.abstractions.event_handler

EventHandler

Bases: Generic[TEvent], ABC

Abstract base class for event handlers. Each handler is responsible for reacting to a specific type of domain event.

Source code in src/castlecraft_engineer/abstractions/event_handler.py
class EventHandler(Generic[TEvent], abc.ABC):
    """
    Abstract base class for event handlers.
    Each handler is responsible for reacting to
    a specific type of domain event.
    """

    @abc.abstractmethod
    async def handle(self, event: TEvent) -> None:
        """
        Handles the logic to execute when the specific event occurs.
        Marked as async to easily accommodate I/O operations
        (like sending emails, updating databases, calling APIs).

        Args:
            event: The event instance to be processed.

        Raises:
            NotImplementedError: This method must be implemented by
                                concrete subclasses.
        """
        raise NotImplementedError

handle(event) abstractmethod async

Handles the logic to execute when the specific event occurs. Marked as async to easily accommodate I/O operations (like sending emails, updating databases, calling APIs).

Parameters:

Name Type Description Default
event TEvent

The event instance to be processed.

required

Raises:

Type Description
NotImplementedError

This method must be implemented by concrete subclasses.

Source code in src/castlecraft_engineer/abstractions/event_handler.py
@abc.abstractmethod
async def handle(self, event: TEvent) -> None:
    """
    Handles the logic to execute when the specific event occurs.
    Marked as async to easily accommodate I/O operations
    (like sending emails, updating databases, calling APIs).

    Args:
        event: The event instance to be processed.

    Raises:
        NotImplementedError: This method must be implemented by
                            concrete subclasses.
    """
    raise NotImplementedError