fix logging
All checks were successful
Build Docker Image / build (push) Successful in 13m47s

This commit is contained in:
2025-02-15 00:35:41 -08:00
parent b7e89d9c22
commit b7aa64935f
8 changed files with 59 additions and 47 deletions

View File

@@ -1,6 +1,10 @@
"""Send commands to mpv via its UNIX socket."""
import socket
import time
import logging
from flask import current_app
from app.config import Config
SOCKET_RETRY_DELAY = 5
@@ -14,14 +18,16 @@ def send_to_mpv(command):
with socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) as client_socket:
client_socket.connect(Config.MPV_SOCKET)
client_socket.sendall(command.encode("utf-8"))
logging.info("Command sent to mpv successfully.")
current_app.logger.info("Command sent to mpv successfully.")
return True
except socket.error as e:
attempts += 1
logging.error(
current_app.logger.error(
f"Failed to connect to socket (attempt {attempts}/{MAX_RETRIES}): {e}. Retrying in {SOCKET_RETRY_DELAY} seconds..."
)
time.sleep(SOCKET_RETRY_DELAY)
logging.error(f"Exceeded maximum retries ({MAX_RETRIES}). Ignoring the request.")
current_app.logger.error(
f"Exceeded maximum retries ({MAX_RETRIES}). Ignoring the request."
)
return False