PR Title Check / check-title (pull_request) Successful in 9s
Code Quality Pipeline / code-quality (pull_request) Failing after 53s
Test Python Package / unit-tests (pull_request) Successful in 1m1s
Test Python Package / integration-tests (pull_request) Successful in 1m44s
Test Python Package / coverage-report (pull_request) Successful in 13s
Provide a generic disk-backed FIFO queue with configurable path, retention, and dedup keys so consumers can buffer items across restarts without optional extras. Co-authored-by: Cursor <cursoragent@cursor.com>
55 lines
1.8 KiB
Python
55 lines
1.8 KiB
Python
"""
|
|
Adapters for various backend repositories (e.g., Redis, Minio).
|
|
|
|
This module exposes concrete implementations for repository interfaces.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import importlib
|
|
from typing import TYPE_CHECKING
|
|
|
|
# Adapters are imported only for static type checkers; runtime loading is deferred below.
|
|
if TYPE_CHECKING:
|
|
from .file_backed_queue_adapter import FileBackedQueueAdapter
|
|
from .memory_queue_adapter import MemoryQueueAdapter
|
|
from .minio_adapter import MinioAdapter
|
|
from .postgres_adapter import PostgresAdapter
|
|
from .redis_adapter import RedisAdapter
|
|
|
|
# Map public adapter names to their defining module and class.
|
|
# Each adapter module fails fast with an install hint if its extra is missing.
|
|
# When adding a new adapter, update this dict and __all__ only.
|
|
_LAZY_EXPORTS = {
|
|
"RedisAdapter": (".redis_adapter", "RedisAdapter"),
|
|
"MinioAdapter": (".minio_adapter", "MinioAdapter"),
|
|
"PostgresAdapter": (".postgres_adapter", "PostgresAdapter"),
|
|
"MemoryQueueAdapter": (".memory_queue_adapter", "MemoryQueueAdapter"),
|
|
"FileBackedQueueAdapter": (
|
|
".file_backed_queue_adapter",
|
|
"FileBackedQueueAdapter",
|
|
),
|
|
}
|
|
|
|
__all__ = [
|
|
"RedisAdapter",
|
|
"MinioAdapter",
|
|
"PostgresAdapter",
|
|
"MemoryQueueAdapter",
|
|
"FileBackedQueueAdapter",
|
|
]
|
|
|
|
|
|
def __getattr__(name: str) -> object:
|
|
"""Load an adapter on first access so the base package installs without backend clients."""
|
|
if name in _LAZY_EXPORTS:
|
|
module_path, attr = _LAZY_EXPORTS[name]
|
|
module = importlib.import_module(module_path, __package__)
|
|
return getattr(module, attr)
|
|
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
|
|
|
|
|
|
def __dir__() -> list[str]:
|
|
"""Expose lazy adapter names in tab completion and dir()."""
|
|
return sorted(__all__)
|