forked from Hay1tsme/artemis
fix: Store reference to async tasks
https://docs.astral.sh/ruff/rules/asyncio-dangling-task/
This commit is contained in:
@ -36,6 +36,7 @@ class DiscordLogHandler(logging.Handler):
|
||||
self._bucket_data: dict["_Level", "LogRecord"] = {
|
||||
logging.WARNING: [],
|
||||
}
|
||||
self._tasks = set()
|
||||
|
||||
def emit(self, record: "LogRecord") -> None:
|
||||
if record.levelno in {logging.CRITICAL, logging.ERROR}:
|
||||
@ -54,7 +55,9 @@ class DiscordLogHandler(logging.Handler):
|
||||
await asyncio.sleep(60)
|
||||
self._send_bucket_data()
|
||||
|
||||
asyncio.ensure_future(schedule())
|
||||
t = asyncio.ensure_future(schedule())
|
||||
self._tasks.add(t)
|
||||
t.add_done_callback(self._tasks.discard)
|
||||
|
||||
|
||||
def _send_bucket_data(self):
|
||||
@ -135,7 +138,9 @@ class DiscordLogHandler(logging.Handler):
|
||||
return " ".join(pings)
|
||||
|
||||
def _post_data(self, body: dict):
|
||||
asyncio.ensure_future(self._post_data_inner(body))
|
||||
t = asyncio.ensure_future(self._post_data_inner(body))
|
||||
self._tasks.add(t)
|
||||
t.add_done_callback(self._tasks.discard)
|
||||
|
||||
async def _post_data_inner(self, body: dict):
|
||||
scale_retry_debounce = 2
|
||||
|
Reference in New Issue
Block a user