fix: Añadir reintentos de conexión MySQL y limitar reinicios de servicios
- get_connection() reintenta hasta 30 veces con delays de 2s - iniciar_todo.py limita reinicios a 3 por servicio con cooldown de 60s - Evitar loops infinitos cuando MySQL no está disponible
This commit is contained in:
@@ -25,6 +25,9 @@ print("🤖 Iniciando Bots de Traducción...")
|
||||
print("=" * 40)
|
||||
|
||||
processes = []
|
||||
restart_counts = {}
|
||||
MAX_RESTARTS = 3
|
||||
RESTART_COOLDOWN = 60
|
||||
|
||||
def start_process(cmd, name, delay_before=0):
|
||||
if delay_before > 0:
|
||||
@@ -72,11 +75,32 @@ signal.signal(signal.SIGTERM, signal_handler)
|
||||
while True:
|
||||
for p, name in processes:
|
||||
if p.poll() is not None:
|
||||
log(f"⚠️ {name} se detuvo, reiniciando...")
|
||||
if name not in restart_counts:
|
||||
restart_counts[name] = {"count": 0, "last_restart": 0}
|
||||
|
||||
current_time = time.time()
|
||||
|
||||
if current_time - restart_counts[name]["last_restart"] > RESTART_COOLDOWN:
|
||||
restart_counts[name]["count"] = 0
|
||||
|
||||
restart_counts[name]["count"] += 1
|
||||
restart_counts[name]["last_restart"] = current_time
|
||||
|
||||
if restart_counts[name]["count"] > MAX_RESTARTS:
|
||||
log(f"⛔ {name} se detuvo {restart_counts[name]['count']} veces. Demasiados reinicios. Esperando {RESTART_COOLDOWN}s...")
|
||||
time.sleep(RESTART_COOLDOWN)
|
||||
restart_counts[name]["count"] = 0
|
||||
continue
|
||||
|
||||
log(f"⚠️ {name} se detuvo (intento {restart_counts[name]['count']}/{MAX_RESTARTS}), reiniciando...")
|
||||
|
||||
delay = 5 if name != "Discord Bot" else 10
|
||||
|
||||
if name == "Discord Bot":
|
||||
p1 = start_process(["python3", "-X", "faulthandler", "-X", "importsys", "botdiscord/bot.py"], "Discord Bot", delay_before=10)
|
||||
p1 = start_process(["python3", "-X", "faulthandler", "-X", "importsys", "botdiscord/bot.py"], "Discord Bot", delay_before=delay)
|
||||
elif name == "Telegram Bot":
|
||||
p2 = start_process(["python3", "-X", "faulthandler", "-X", "importsys", "bottelegram/telegram_bot.py"], "Telegram Bot", delay_before=5)
|
||||
p2 = start_process(["python3", "-X", "faulthandler", "-X", "importsys", "bottelegram/telegram_bot.py"], "Telegram Bot", delay_before=delay)
|
||||
elif name == "Panel Web":
|
||||
p3 = start_process(["python3", "-X", "faulthandler", "-X", "importsys", "panel/main.py"], "Panel Web", delay_before=0)
|
||||
|
||||
time.sleep(5)
|
||||
|
||||
Reference in New Issue
Block a user