diff options
| author | lonkaars <l.leblansch@gmail.com> | 2021-02-22 12:48:38 +0100 | 
|---|---|---|
| committer | lonkaars <l.leblansch@gmail.com> | 2021-02-22 12:48:38 +0100 | 
| commit | 32aaaf92f2c06214abdc93e3cede07e067df6b88 (patch) | |
| tree | 1b98d9e7605278311aa76880614ba17361f69285 /api/game/cleanup.py | |
| parent | ae4e74ccde82388cca5e874539bb132e23fc1e92 (diff) | |
added columns to games + cleanup function
Diffstat (limited to 'api/game/cleanup.py')
| -rw-r--r-- | api/game/cleanup.py | 17 | 
1 files changed, 17 insertions, 0 deletions
| diff --git a/api/game/cleanup.py b/api/game/cleanup.py new file mode 100644 index 0000000..2b09142 --- /dev/null +++ b/api/game/cleanup.py @@ -0,0 +1,17 @@ +from db import cursor, connection +import threading + +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) + +def set_interval(func, sec): # https://stackoverflow.com/questions/2697039/python-equivalent-of-setinterval +    def func_wrapper(): +        set_interval(func, sec) +        func() +    t = threading.Timer(sec, func_wrapper) +    t.start() +    return t + +set_interval(cleanup, 5 * 60) |