Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,21 @@ def _sweep_disabled() -> bool:
with its track list persisted permanently in ~/Documents/StemDeck. The 24h
job TTL sweep -- a sensible disk-hygiene default for the shared server/Docker
deployment -- would wrongly purge stems the user kept, leaving orphaned
library entries that ask to "re-upload to restore". So skip the sweep under
the desktop shell (STEMDECK_DESKTOP=1); the user manages disk via Trash."""
return os.environ.get("STEMDECK_DESKTOP") == "1"
library entries that ask to "re-upload to restore".

So skip the sweep under the desktop shell (STEMDECK_DESKTOP=1), or when a
self-hosted deployment opts into a persistent library
(STEMDECK_PERSIST_LIBRARY=1 -- set by default in run.sh). The user manages
disk via Trash. Shared/Docker deployments that set neither keep the sweep."""
return (
os.environ.get("STEMDECK_DESKTOP") == "1"
or os.environ.get("STEMDECK_PERSIST_LIBRARY") == "1"
)


async def _sweep_loop() -> None:
if _sweep_disabled():
_log.info("desktop mode: job TTL sweep disabled (library is user-managed)")
_log.info("job TTL sweep disabled (persistent library; user-managed)")
return
while True:
try:
Expand Down
4 changes: 4 additions & 0 deletions run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ cd "$(dirname "$0")"
HOST="${HOST:-0.0.0.0}"
PORT="${PORT:-8080}"
RELOAD="${RELOAD:-0}"
# Treat the self-hosted server as a persistent, user-managed library (like the
# desktop app): opt out of the 24h job TTL sweep so processed tracks are not
# auto-deleted. Override with STEMDECK_PERSIST_LIBRARY=0 for disk-hygiene mode.
export STEMDECK_PERSIST_LIBRARY="${STEMDECK_PERSIST_LIBRARY:-1}"
FOREGROUND="${FOREGROUND:-0}"
PID_FILE=".run/uvicorn.pid"
LOG_FILE=".run/uvicorn.log"
Expand Down
13 changes: 13 additions & 0 deletions tests/test_sweep.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,25 @@ def test_sweep_disabled_under_desktop(monkeypatch):
user's curated library isn't purged; the server/Docker default keeps it."""
from app.main import _sweep_disabled

monkeypatch.delenv("STEMDECK_PERSIST_LIBRARY", raising=False)
monkeypatch.setenv("STEMDECK_DESKTOP", "1")
assert _sweep_disabled() is True
monkeypatch.delenv("STEMDECK_DESKTOP", raising=False)
assert _sweep_disabled() is False


def test_sweep_disabled_under_persistent_library(monkeypatch):
"""A self-hosted server (run.sh) opts into a persistent library
(STEMDECK_PERSIST_LIBRARY=1) so its processed tracks aren't purged."""
from app.main import _sweep_disabled

monkeypatch.delenv("STEMDECK_DESKTOP", raising=False)
monkeypatch.setenv("STEMDECK_PERSIST_LIBRARY", "1")
assert _sweep_disabled() is True
monkeypatch.delenv("STEMDECK_PERSIST_LIBRARY", raising=False)
assert _sweep_disabled() is False


@pytest.mark.asyncio
async def test_sweep_loop_returns_immediately_under_desktop(monkeypatch):
"""In desktop mode the loop returns at once instead of entering the hourly
Expand Down