various/stale

This commit is contained in:
2026-01-25 13:14:00 -05:00
parent 10ccf8c8eb
commit 97fd7dd67d
14 changed files with 501 additions and 64 deletions

View File

@@ -5,6 +5,7 @@ import datetime
import os
import random
import asyncio
import subprocess
from uuid import uuid4 as uuid
from typing import Union, Optional, Iterable
from aiohttp import ClientSession, ClientTimeout
@@ -391,6 +392,39 @@ class RadioUtil:
traceback.print_exc()
return "Not Found"
async def _restart_liquidsoap_when_ready(self) -> None:
"""Poll server until responsive, then restart Liquidsoap."""
max_attempts = 60
for attempt in range(max_attempts):
try:
async with ClientSession() as session:
async with session.get(
"http://127.0.0.1:52111/",
timeout=ClientTimeout(total=3),
) as resp:
logging.debug("Server check attempt %d: status %d", attempt + 1, resp.status)
if resp.status < 500:
logging.info("Server is ready (attempt %d)", attempt + 1)
break
except Exception as e:
logging.debug("Server check attempt %d failed: %s", attempt + 1, str(e))
await asyncio.sleep(1)
else:
logging.warning("Server readiness check timed out, restarting Liquidsoap anyway")
try:
logging.info("Restarting Liquidsoap...")
subprocess.Popen(
["./restart.sh"],
cwd="/home/kyle/ls",
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
start_new_session=True,
)
logging.info("Liquidsoap restart initiated")
except Exception as e:
logging.error("Error starting Liquidsoap restart: %s", str(e))
async def load_playlists(self) -> None:
"""Load Playlists"""
try:
@@ -487,10 +521,8 @@ class RadioUtil:
"""Loading Complete"""
self.playlists_loaded = True
# Request skip from LS to bring streams current
for playlist in self.playlists:
logging.info("Skipping: %s", playlist)
await self._ls_skip(playlist)
# Restart Liquidsoap once server is responsive (fire and forget)
asyncio.create_task(self._restart_liquidsoap_when_ready())
except Exception as e:
logging.info("Playlist load failed: %s", str(e))
traceback.print_exc()