anonstream/anonstream/access.py

27 行
605 B
Python
Raw 通常表示 履歴

# SPDX-FileCopyrightText: 2022 n9k <https://gitler.moe/ninya9k>
2022-06-24 12:31:01 +09:00
# SPDX-License-Identifier: AGPL-3.0-or-later
2022-06-22 14:00:43 +09:00
import time
from quart import current_app
CONFIG = current_app.config
2022-06-22 14:00:43 +09:00
FAILURES = current_app.failures
def add_failure(message):
timestamp = time.time_ns() // 1_000_000
while timestamp in FAILURES:
timestamp += 1
FAILURES[timestamp] = message
while len(FAILURES) > CONFIG['MAX_FAILURES']:
FAILURES.popitem(last=False)
2022-06-22 14:00:43 +09:00
return timestamp
def pop_failure(failure_id):
try:
return FAILURES.pop(failure_id)
except KeyError:
return None