From 8cbd247d90c75c92ae45df458a29144c86ac5de7 Mon Sep 17 00:00:00 2001 From: lonkaars Date: Mon, 22 Feb 2021 19:22:11 +0100 Subject: fix stale game cleanup --- api/game/cleanup.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/api/game/cleanup.py b/api/game/cleanup.py index 2b09142..3c285e1 100644 --- a/api/game/cleanup.py +++ b/api/game/cleanup.py @@ -1,10 +1,13 @@ from db import cursor, connection import threading +import time def cleanup(): now = int( time.time() * 1000 ) - old_games = cursor.execute("select game_id from games where (status = \"wait_for_opponent\" or status = \"in_progress\") and last_activity < ?", [now - 5 * 60 * 1e3]) - print(old_games) + old_games = cursor.execute("select game_id from games where (status = \"wait_for_opponent\" or status = \"in_progress\") and last_activity < ?", [now - 5 * 60 * 1e3]).fetchall() + for game_id in old_games: + cursor.execute("delete from games where game_id = ?", [game_id[0]]) + connection.commit() def set_interval(func, sec): # https://stackoverflow.com/questions/2697039/python-equivalent-of-setinterval def func_wrapper(): @@ -15,3 +18,4 @@ def set_interval(func, sec): # https://stackoverflow.com/questions/2697039/pytho return t set_interval(cleanup, 5 * 60) + -- cgit v1.2.3