This commit is contained in:
14
app/mpv.py
14
app/mpv.py
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user