Show cleanup stats

This commit is contained in:
Nexus 2023-04-09 21:49:03 +01:00
parent 42682c6378
commit 2eb9adee7b
Signed by: nex
GPG key ID: 0FA334385D0B689F

View file

@ -72,9 +72,12 @@ async def authenticate(req: Request, code: str = None, state: str = None):
if value in app.state.states: if value in app.state.states:
print("Generated a state that already exists. Cleaning up", file=sys.stderr) print("Generated a state that already exists. Cleaning up", file=sys.stderr)
# remove any states older than 5 minutes # remove any states older than 5 minutes
removed = 0
for _value in list(app.state.states): for _value in list(app.state.states):
if (datetime.now() - app.state.states[_value]).total_seconds() > 300: if (datetime.now() - app.state.states[_value]).total_seconds() > 300:
del app.state.states[_value] del app.state.states[_value]
removed += 1
print(f"Removed {removed} states.", file=sys.stderr)
if value in app.state.states: if value in app.state.states:
assert value not in app.state.states, "Generated a state that already exists and could not free any slots." assert value not in app.state.states, "Generated a state that already exists and could not free any slots."