fix: Lint fixes of services
All checks were successful
Backend CI / test (push) Successful in 3m59s

This commit is contained in:
JSC
2025-08-01 01:27:47 +02:00
parent 95ccb76233
commit a10111793c
12 changed files with 237 additions and 160 deletions

View File

@@ -23,7 +23,8 @@ class VLCPlayerService:
"""Service for launching VLC instances via subprocess to play sounds."""
def __init__(
self, db_session_factory: Callable[[], AsyncSession] | None = None,
self,
db_session_factory: Callable[[], AsyncSession] | None = None,
) -> None:
"""Initialize the VLC player service."""
self.vlc_executable = self._find_vlc_executable()
@@ -52,7 +53,7 @@ class VLCPlayerService:
# For "vlc", try to find it in PATH
if path == "vlc":
result = subprocess.run(
["which", "vlc"],
["which", "vlc"], # noqa: S607
capture_output=True,
check=False,
text=True,
@@ -112,13 +113,19 @@ class VLCPlayerService:
# Record play count and emit event
if self.db_session_factory and sound.id:
asyncio.create_task(self._record_play_count(sound.id, sound.name))
return True
task = asyncio.create_task(
self._record_play_count(sound.id, sound.name),
)
# Store reference to prevent garbage collection
self._background_tasks = getattr(self, "_background_tasks", set())
self._background_tasks.add(task)
task.add_done_callback(self._background_tasks.discard)
except Exception:
logger.exception("Failed to launch VLC for sound %s", sound.name)
return False
else:
return True
async def stop_all_vlc_instances(self) -> dict[str, Any]:
"""Stop all running VLC processes by killing them.
@@ -287,7 +294,8 @@ class VLCPlayerService:
logger.info("Broadcasted sound_played event for sound %s", sound_id)
except Exception:
logger.exception(
"Failed to broadcast sound_played event for sound %s", sound_id,
"Failed to broadcast sound_played event for sound %s",
sound_id,
)
except Exception:
@@ -297,7 +305,6 @@ class VLCPlayerService:
await session.close()
# Global VLC player service instance
vlc_player_service: VLCPlayerService | None = None
@@ -310,3 +317,4 @@ def get_vlc_player_service(
if vlc_player_service is None:
vlc_player_service = VLCPlayerService(db_session_factory)
return vlc_player_service
return vlc_player_service