Skip to content

NotificationService

🛈 DocStrings

Sends notifications based on various events.

Source code in src/anyenv/signals/examples.py
class NotificationService:
    """Sends notifications based on various events."""

    def __init__(self, user_service: UserService, file_service: FileService) -> None:
        user_service.user_created.connect(self.on_user_created)
        file_service.file_created.connect(self.on_file_created)

    async def on_user_created(self, user: User) -> None:
        """Handle user creation events."""
        print(f"NOTIFICATION: Welcome {user.name}!")

    async def on_file_created(self, event: FileEvent) -> None:
        """Handle file creation events."""
        print(f"NOTIFICATION: File created: {event.path} ({event.size} bytes)")

on_file_created async

on_file_created(event: FileEvent) -> None

Handle file creation events.

Source code in src/anyenv/signals/examples.py
async def on_file_created(self, event: FileEvent) -> None:
    """Handle file creation events."""
    print(f"NOTIFICATION: File created: {event.path} ({event.size} bytes)")

on_user_created async

on_user_created(user: User) -> None

Handle user creation events.

Source code in src/anyenv/signals/examples.py
async def on_user_created(self, user: User) -> None:
    """Handle user creation events."""
    print(f"NOTIFICATION: Welcome {user.name}!")

:fa-brands-github: Show source on GitHub