feat: auto delete server if it is inactive for more than 5 minutes, minor fix
This commit is contained in:
@ -20,6 +20,10 @@ class CommandService:
|
||||
}
|
||||
print(f"[{datetime.now()}] Добавлена команда: {command_data.command} "
|
||||
f"для сервера {command_data.server_ip}")
|
||||
|
||||
# Обновляем last_activity для сервера
|
||||
await self._update_server_activity(command_data.server_ip)
|
||||
|
||||
return {"status": "success", "command_id": command_id}
|
||||
except Exception as e:
|
||||
raise HTTPException(status_code=400, detail=str(e))
|
||||
@ -47,3 +51,14 @@ class CommandService:
|
||||
return {"status": "success", "commands": commands}
|
||||
except Exception as e:
|
||||
raise HTTPException(status_code=400, detail=str(e))
|
||||
|
||||
async def _update_server_activity(self, server_ip):
|
||||
"""Обновляет время последней активности для сервера"""
|
||||
from app.db.database import db
|
||||
game_servers_collection = db.game_servers
|
||||
|
||||
await game_servers_collection.update_one(
|
||||
{"ip": server_ip},
|
||||
{"$set": {"last_activity": datetime.utcnow()}},
|
||||
upsert=False # Не создаем новый сервер, только обновляем существующий
|
||||
)
|
||||
|
Reference in New Issue
Block a user