python_outbox_core.publisher.base ================================= .. py:module:: python_outbox_core.publisher.base .. autoapi-nested-parse:: Base publisher/worker for outbox event publishing. Best Practices Applied: 1. Template Method pattern - reusable core, custom schedule 2. Batch processing for efficiency 3. Dependency injection for error handling & metrics; error handling with structured logging 4. Single Responsibility - only batch orchestration; only publishes, doesn't schedule 5. Open/Closed principle - extend, don't modify References: - Template Method: https://refactoring.guru/design-patterns/template-method - Competing Consumers: https://www.enterpriseintegrationpatterns.com/patterns/messaging/CompetingConsumers.html Classes ------- .. autoapisummary:: python_outbox_core.publisher.base.OutboxPublisherBase Module Contents --------------- .. py:class:: OutboxPublisherBase(repository: python_outbox_core.repository.IOutboxRepository, publisher: python_outbox_core.publisher.interface.IEventPublisher, error_handler: python_outbox_core.publisher.error_handler.OutboxErrorHandler | None = None, metrics: python_outbox_core.publisher.metrics.OutboxMetrics | None = None) Bases: :py:obj:`abc.ABC` Reusable outbox worker logic. Handles: - Batch fetching from outbox - Publishing to broker (via IEventPublisher) - Marking events as published (via IOutboxRepository) - Error handling (via OutboxErrorHandler) - Metrics/logging (via OutboxMetrics) Projects extend this and implement schedule_publishing(). .. py:attribute:: repository .. py:attribute:: publisher .. py:attribute:: error_handler .. py:attribute:: metrics .. py:method:: publish_batch(limit: int = 100) -> int :async: Fetch and publish a batch of unpublished events. Args: limit: Max events to process in this batch Returns: Number of successfully published events .. py:method:: schedule_publishing() -> None :abstractmethod: :async: Implement your scheduling strategy. Options: - Infinite loop: while True + asyncio.sleep() - Celery beat: Distributed scheduling - K8s CronJob: Container-based scheduling