Add QueueRepositoryInterface with memory and file-backed adapters.

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 <[email protected]>
This commit is contained in:
Brian Bjarke Jensen
2026-07-16 20:18:00 +02:00
co-authored by Cursor
parent 1babb52d09
commit a768474892
15 changed files with 1092 additions and 13 deletions
+56
View File
@@ -0,0 +1,56 @@
"""Unit tests for FileQueueConfig."""
from __future__ import annotations
from pathlib import Path
import pytest
from python_repositories.config import FileQueueConfig
def test_defaults() -> None:
config = FileQueueConfig(path=Path("/tmp/queue.jsonl"))
assert config.path == Path("/tmp/queue.jsonl")
assert config.max_age_hours == 24
assert config.dedup_keys == ()
assert config.age_key is None
def test_from_env_loads_path(monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.setenv("FILE_QUEUE_PATH", "/data/items.jsonl")
monkeypatch.delenv("FILE_QUEUE_MAX_AGE_HOURS", raising=False)
config = FileQueueConfig.from_env(use_dotenv=False)
assert config.path == Path("/data/items.jsonl")
assert config.max_age_hours == 24
def test_from_env_loads_max_age_hours(monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.setenv("FILE_QUEUE_PATH", "/data/items.jsonl")
monkeypatch.setenv("FILE_QUEUE_MAX_AGE_HOURS", "48")
config = FileQueueConfig.from_env(use_dotenv=False)
assert config.max_age_hours == 48
def test_from_env_raises_when_path_missing(monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.delenv("FILE_QUEUE_PATH", raising=False)
with pytest.raises(Exception):
FileQueueConfig.from_env(use_dotenv=False)
def test_from_env_respects_custom_env_var_names(
monkeypatch: pytest.MonkeyPatch,
) -> None:
monkeypatch.setenv("CUSTOM_QUEUE_PATH", "/custom/q.jsonl")
monkeypatch.setenv("CUSTOM_MAX_AGE", "12")
config = FileQueueConfig.from_env(
"CUSTOM_QUEUE_PATH",
max_age_hours_env_var_name="CUSTOM_MAX_AGE",
dedup_keys=("id",),
age_key="created_at",
use_dotenv=False,
)
assert config.path == Path("/custom/q.jsonl")
assert config.max_age_hours == 12
assert config.dedup_keys == ("id",)
assert config.age_key == "created_at"