2023-02-24 07:32:42 +09:00
|
|
|
# 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
|
|
|
|
|
2022-06-22 17:35:35 +09:00
|
|
|
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
|
2022-06-22 17:35:35 +09:00
|
|
|
|
|
|
|
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
|