feat: config-aware registry gating Qobuz on credentials; wire config into worker
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
import time
|
import time
|
||||||
|
|
||||||
from lyra_worker.claim import claim_next
|
from lyra_worker.claim import claim_next
|
||||||
|
from lyra_worker.config import get_config
|
||||||
from lyra_worker.db import wait_for_db
|
from lyra_worker.db import wait_for_db
|
||||||
from lyra_worker.pipeline import run_pipeline
|
from lyra_worker.pipeline import run_pipeline
|
||||||
from lyra_worker.registry import build_adapters
|
from lyra_worker.registry import build_adapters
|
||||||
@@ -10,7 +11,8 @@ IDLE_SLEEP = 2.0
|
|||||||
|
|
||||||
def run_forever() -> None:
|
def run_forever() -> None:
|
||||||
conn = wait_for_db()
|
conn = wait_for_db()
|
||||||
adapters = build_adapters()
|
adapters = build_adapters(get_config(conn))
|
||||||
|
print(f"worker: {len(adapters)} adapter(s) enabled: {[a.name for a in adapters]}", flush=True)
|
||||||
print("worker: waiting for jobs", flush=True)
|
print("worker: waiting for jobs", flush=True)
|
||||||
try:
|
try:
|
||||||
while True:
|
while True:
|
||||||
|
|||||||
@@ -1,12 +1,18 @@
|
|||||||
|
from lyra_worker.adapters._streamrip import StreamripClient
|
||||||
from lyra_worker.adapters._ytdlp import YtDlpClient
|
from lyra_worker.adapters._ytdlp import YtDlpClient
|
||||||
from lyra_worker.adapters.base import SourceAdapter
|
from lyra_worker.adapters.base import SourceAdapter
|
||||||
|
from lyra_worker.adapters.qobuz import QobuzAdapter
|
||||||
from lyra_worker.adapters.youtube import YouTubeAdapter
|
from lyra_worker.adapters.youtube import YouTubeAdapter
|
||||||
|
|
||||||
|
|
||||||
def build_adapters() -> list[SourceAdapter]:
|
def build_adapters(config: dict) -> list[SourceAdapter]:
|
||||||
"""The enabled real source adapters, best-tier first.
|
"""Real source adapters, best-tier first, filtered to those that are configured.
|
||||||
|
|
||||||
Only real, usable adapters are returned. Plan 3c/3d add Qobuz (streamrip)
|
An adapter is included only if its health() is true (e.g. Qobuz requires
|
||||||
and Soulseek (slskd), each gated on its config being present via health().
|
credentials in config). Plan 3d adds Soulseek (slskd) the same way.
|
||||||
"""
|
"""
|
||||||
return [YouTubeAdapter(YtDlpClient())]
|
candidates: list[SourceAdapter] = [
|
||||||
|
QobuzAdapter(StreamripClient(config)),
|
||||||
|
YouTubeAdapter(YtDlpClient()),
|
||||||
|
]
|
||||||
|
return [a for a in candidates if a.health()]
|
||||||
|
|||||||
@@ -1,17 +1,30 @@
|
|||||||
|
from lyra_worker.adapters.qobuz import QobuzAdapter
|
||||||
from lyra_worker.adapters.youtube import YouTubeAdapter
|
from lyra_worker.adapters.youtube import YouTubeAdapter
|
||||||
from lyra_worker.registry import build_adapters
|
from lyra_worker.registry import build_adapters
|
||||||
|
|
||||||
|
QOBUZ_CFG = {"qobuz.email": "me@example.com", "qobuz.password": "secret"}
|
||||||
|
|
||||||
def test_registry_returns_real_youtube_adapter():
|
|
||||||
adapters = build_adapters()
|
def test_youtube_always_present_qobuz_skipped_without_config():
|
||||||
|
adapters = build_adapters({})
|
||||||
names = [a.name for a in adapters]
|
names = [a.name for a in adapters]
|
||||||
assert "youtube" in names
|
assert "youtube" in names
|
||||||
|
assert "qobuz" not in names # no creds -> health() false -> excluded
|
||||||
|
|
||||||
|
|
||||||
|
def test_qobuz_included_when_configured():
|
||||||
|
adapters = build_adapters(QOBUZ_CFG)
|
||||||
|
names = [a.name for a in adapters]
|
||||||
|
assert "qobuz" in names
|
||||||
|
assert "youtube" in names
|
||||||
|
qz = next(a for a in adapters if a.name == "qobuz")
|
||||||
yt = next(a for a in adapters if a.name == "youtube")
|
yt = next(a for a in adapters if a.name == "youtube")
|
||||||
|
assert isinstance(qz, QobuzAdapter)
|
||||||
assert isinstance(yt, YouTubeAdapter)
|
assert isinstance(yt, YouTubeAdapter)
|
||||||
assert yt.tier == 2
|
|
||||||
assert yt.health() is True
|
|
||||||
|
|
||||||
|
|
||||||
def test_registry_adapter_names_are_unique():
|
def test_adapter_names_unique_and_qobuz_first():
|
||||||
names = [a.name for a in build_adapters()]
|
adapters = build_adapters(QOBUZ_CFG)
|
||||||
|
names = [a.name for a in adapters]
|
||||||
assert len(names) == len(set(names))
|
assert len(names) == len(set(names))
|
||||||
|
assert names[0] == "qobuz" # tier 0 listed first
|
||||||
|
|||||||
Reference in New Issue
Block a user