diff options
author | lonkaars <l.leblansch@gmail.com> | 2021-02-22 19:22:11 +0100 |
---|---|---|
committer | lonkaars <l.leblansch@gmail.com> | 2021-02-22 19:22:11 +0100 |
commit | 8cbd247d90c75c92ae45df458a29144c86ac5de7 (patch) | |
tree | 170508e2702e9c5b2bfcbeca65ca42eeeac61ffe /api/game/cleanup.py | |
parent | 495d28fc82db51731768cd61e1d233bb10acbfd6 (diff) |
fix stale game cleanup
Diffstat (limited to 'api/game/cleanup.py')
-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) + |