diff options
Diffstat (limited to 'api')
-rw-r--r-- | api/game/cleanup.py | 8 |
1 files 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) + |