update code structure and get session on each query
All checks were successful
Build Docker Image / build (push) Successful in 12m54s
All checks were successful
Build Docker Image / build (push) Successful in 12m54s
This commit is contained in:
27
app/mpv.py
Normal file
27
app/mpv.py
Normal file
@@ -0,0 +1,27 @@
|
||||
import socket
|
||||
import time
|
||||
import logging
|
||||
from app.config import Config
|
||||
|
||||
SOCKET_RETRY_DELAY = 5
|
||||
MAX_RETRIES = 10
|
||||
|
||||
|
||||
def send_to_mpv(command):
|
||||
attempts = 0
|
||||
while attempts < MAX_RETRIES:
|
||||
try:
|
||||
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.")
|
||||
return True
|
||||
except socket.error as e:
|
||||
attempts += 1
|
||||
logging.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.")
|
||||
return False
|
||||
Reference in New Issue
Block a user