Use new wrapper for creating background tasks

This commit is contained in:
Tulir Asokan 2023-02-12 12:51:19 +02:00
parent c0c7b58a3f
commit e73869bb19
4 changed files with 9 additions and 5 deletions

View File

@ -15,7 +15,7 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>.
from __future__ import annotations
from typing import TYPE_CHECKING, Any, AsyncGenerator, AsyncIterable, Awaitable, Callable, cast
from typing import TYPE_CHECKING, Any, AsyncGenerator, Awaitable, Callable, cast
from collections import defaultdict
import asyncio
import logging
@ -43,6 +43,7 @@ from mautrix.types import (
)
from mautrix.util.async_getter_lock import async_getter_lock
from mautrix.util.logging import TraceLogger
from mautrix.util import background_task
from .db import Client as DBClient
from .matrix import MaubotMatrixClient
@ -254,7 +255,7 @@ class Client(DBClient):
self.log.warning(
f"Failed to get /account/whoami, retrying in {(try_n + 1) * 10}s: {e}"
)
_ = asyncio.create_task(self.start(try_n + 1))
background_task.create(self.start(try_n + 1))
return
if whoami.user_id != self.id:
self.log.error(f"User ID mismatch: expected {self.id}, but got {whoami.user_id}")

View File

@ -32,6 +32,7 @@ from mautrix.util.async_db import Database, Scheme, UpgradeTable
from mautrix.util.async_getter_lock import async_getter_lock
from mautrix.util.config import BaseProxyConfig, RecursiveDict
from mautrix.util.logging import TraceLogger
from mautrix.util import background_task
from .client import Client
from .db import DatabaseEngine, Instance as DBInstance
@ -280,7 +281,7 @@ class PluginInstance(DBInstance):
if val != self.config_str:
self.config_str = val
self.log.debug("Creating background task to save updated config")
asyncio.create_task(self.update())
background_task.create(self.update())
async def start_database(
self, upgrade_table: UpgradeTable | None = None, actually_start: bool = True

View File

@ -22,6 +22,8 @@ import logging
from aiohttp import web, web_ws
from mautrix.util import background_task
from .auth import is_valid_token
from .base import routes
@ -142,7 +144,7 @@ async def log_websocket(request: web.Request) -> web.WebSocketResponse:
await ws.close(code=4000)
log.debug(f"Connection from {request.remote} terminated due to no authentication")
asyncio.create_task(close_if_not_authenticated())
background_task.create(close_if_not_authenticated())
try:
msg: web_ws.WSMessage

View File

@ -1,4 +1,4 @@
mautrix>=0.16.2,<0.20
mautrix>=0.19.4,<0.20
aiohttp>=3,<4
yarl>=1,<2
SQLAlchemy>=1,<1.4