mirror of
https://github.com/maubot/maubot.git
synced 2024-10-01 01:06:10 -04:00
Use new wrapper for creating background tasks
This commit is contained in:
parent
c0c7b58a3f
commit
e73869bb19
@ -15,7 +15,7 @@
|
|||||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
from __future__ import annotations
|
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
|
from collections import defaultdict
|
||||||
import asyncio
|
import asyncio
|
||||||
import logging
|
import logging
|
||||||
@ -43,6 +43,7 @@ from mautrix.types import (
|
|||||||
)
|
)
|
||||||
from mautrix.util.async_getter_lock import async_getter_lock
|
from mautrix.util.async_getter_lock import async_getter_lock
|
||||||
from mautrix.util.logging import TraceLogger
|
from mautrix.util.logging import TraceLogger
|
||||||
|
from mautrix.util import background_task
|
||||||
|
|
||||||
from .db import Client as DBClient
|
from .db import Client as DBClient
|
||||||
from .matrix import MaubotMatrixClient
|
from .matrix import MaubotMatrixClient
|
||||||
@ -254,7 +255,7 @@ class Client(DBClient):
|
|||||||
self.log.warning(
|
self.log.warning(
|
||||||
f"Failed to get /account/whoami, retrying in {(try_n + 1) * 10}s: {e}"
|
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
|
return
|
||||||
if whoami.user_id != self.id:
|
if whoami.user_id != self.id:
|
||||||
self.log.error(f"User ID mismatch: expected {self.id}, but got {whoami.user_id}")
|
self.log.error(f"User ID mismatch: expected {self.id}, but got {whoami.user_id}")
|
||||||
|
@ -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.async_getter_lock import async_getter_lock
|
||||||
from mautrix.util.config import BaseProxyConfig, RecursiveDict
|
from mautrix.util.config import BaseProxyConfig, RecursiveDict
|
||||||
from mautrix.util.logging import TraceLogger
|
from mautrix.util.logging import TraceLogger
|
||||||
|
from mautrix.util import background_task
|
||||||
|
|
||||||
from .client import Client
|
from .client import Client
|
||||||
from .db import DatabaseEngine, Instance as DBInstance
|
from .db import DatabaseEngine, Instance as DBInstance
|
||||||
@ -280,7 +281,7 @@ class PluginInstance(DBInstance):
|
|||||||
if val != self.config_str:
|
if val != self.config_str:
|
||||||
self.config_str = val
|
self.config_str = val
|
||||||
self.log.debug("Creating background task to save updated config")
|
self.log.debug("Creating background task to save updated config")
|
||||||
asyncio.create_task(self.update())
|
background_task.create(self.update())
|
||||||
|
|
||||||
async def start_database(
|
async def start_database(
|
||||||
self, upgrade_table: UpgradeTable | None = None, actually_start: bool = True
|
self, upgrade_table: UpgradeTable | None = None, actually_start: bool = True
|
||||||
|
@ -22,6 +22,8 @@ import logging
|
|||||||
|
|
||||||
from aiohttp import web, web_ws
|
from aiohttp import web, web_ws
|
||||||
|
|
||||||
|
from mautrix.util import background_task
|
||||||
|
|
||||||
from .auth import is_valid_token
|
from .auth import is_valid_token
|
||||||
from .base import routes
|
from .base import routes
|
||||||
|
|
||||||
@ -142,7 +144,7 @@ async def log_websocket(request: web.Request) -> web.WebSocketResponse:
|
|||||||
await ws.close(code=4000)
|
await ws.close(code=4000)
|
||||||
log.debug(f"Connection from {request.remote} terminated due to no authentication")
|
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:
|
try:
|
||||||
msg: web_ws.WSMessage
|
msg: web_ws.WSMessage
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
mautrix>=0.16.2,<0.20
|
mautrix>=0.19.4,<0.20
|
||||||
aiohttp>=3,<4
|
aiohttp>=3,<4
|
||||||
yarl>=1,<2
|
yarl>=1,<2
|
||||||
SQLAlchemy>=1,<1.4
|
SQLAlchemy>=1,<1.4
|
||||||
|
Loading…
Reference in New Issue
Block a user