feat(server): re-export URL helpers; callable job done_message

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-06-08 23:54:49 -07:00
parent aa9d177ed1
commit ca36d2bb27
4 changed files with 26 additions and 3 deletions

View File

@@ -48,7 +48,8 @@ def get_job(job_id: str) -> Optional["Job"]:
return JOBS.get(job_id) return JOBS.get(job_id)
def run_job(job_id: str, fn: Callable[[], dict], done_message: str, def run_job(job_id: str, fn: Callable[[], dict],
done_message: "str | Callable[[dict], str]",
fail_message: str = "Something went wrong while fetching.") -> None: fail_message: str = "Something went wrong while fetching.") -> None:
def _task(): def _task():
job = JOBS.get(job_id) job = JOBS.get(job_id)
@@ -57,7 +58,8 @@ def run_job(job_id: str, fn: Callable[[], dict], done_message: str,
_touch(job, status="running") _touch(job, status="running")
try: try:
result = fn() result = fn()
_touch(job, status="done", result=result, message=done_message) msg = done_message(result) if callable(done_message) else done_message
_touch(job, status="done", result=result, message=msg)
except Exception as e: # noqa: BLE001 — record any failure on the job except Exception as e: # noqa: BLE001 — record any failure on the job
_touch(job, status="failed", error=f"{type(e).__name__}: {e}", _touch(job, status="failed", error=f"{type(e).__name__}: {e}",
message=fail_message) message=fail_message)

View File

@@ -24,6 +24,11 @@ act_youtube = _mod.act_youtube
act_lidarr_album = _mod.act_lidarr_album act_lidarr_album = _mod.act_lidarr_album
act_lidarr_artist = _mod.act_lidarr_artist act_lidarr_artist = _mod.act_lidarr_artist
QUALITY_CHOICES = _mod.QUALITY_CHOICES QUALITY_CHOICES = _mod.QUALITY_CHOICES
is_url = _mod.is_url
is_playlist_url = _mod.is_playlist_url
download_playlist = _mod.download_playlist
download_single = _mod.download_single
__all__ = ["Hit", "build_combined_hits", "pick", "act_youtube", __all__ = ["Hit", "build_combined_hits", "pick", "act_youtube",
"act_lidarr_album", "act_lidarr_artist", "QUALITY_CHOICES"] "act_lidarr_album", "act_lidarr_artist", "QUALITY_CHOICES",
"is_url", "is_playlist_url", "download_playlist", "download_single"]

View File

@@ -51,5 +51,13 @@ def test_eviction_keeps_within_cap():
jobs.JOBS.clear() jobs.JOBS.clear()
def test_run_job_callable_done_message():
job = jobs.create_job(hit={}, message="m")
jobs.run_job(job.id, lambda: {"ok": 2, "total": 3},
done_message=lambda res: f"{res['ok']}/{res['total']} done")
j = _wait(job.id, "done")
assert j.message == "2/3 done"
def teardown_module(): def teardown_module():
jobs.JOBS.clear() jobs.JOBS.clear()

View File

@@ -0,0 +1,8 @@
import server.mf as smf
def test_url_helpers_reexported():
assert callable(smf.is_url)
assert callable(smf.is_playlist_url)
assert callable(smf.download_playlist)
assert callable(smf.download_single)