Use new wrapper for creating background tasks

This commit is contained in:
Tulir Asokan
2023-02-11 22:41:15 +02:00
parent be6f6bbfac
commit f7b694c9e4
8 changed files with 27 additions and 24 deletions
+2 -1
View File
@@ -38,6 +38,7 @@ from telethon.errors import (
)
from mautrix.bridge import InvalidAccessToken, OnlyLoginSelf
from mautrix.util import background_task
from mautrix.util.format_duration import format_duration
from ...commands.telegram.auth import enter_password
@@ -199,7 +200,7 @@ class AuthAPI(abc.ABC):
existing_user = await User.get_by_tgid(user_info.id)
if existing_user and existing_user != user:
await existing_user.log_out()
asyncio.create_task(user.post_login(user_info, first_login=True))
background_task.create(user.post_login(user_info, first_login=True))
if user.command_status and user.command_status["action"] == "Login":
user.command_status = None
@@ -32,6 +32,7 @@ from mautrix.appservice import AppService
from mautrix.client import Client
from mautrix.errors import IntentError, MatrixRequestError
from mautrix.types import UserID
from mautrix.util import background_task
from ...commands.portal.util import get_initial_state, user_has_power_level
from ...portal import Portal
@@ -227,7 +228,7 @@ class ProvisioningAPI(AuthAPI):
portal.photo_id = ""
await portal.save()
asyncio.create_task(portal.update_matrix_room(user, entity, levels=levels))
background_task.create(portal.update_matrix_room(user, entity, levels=levels))
return web.Response(status=202, body="{}")
@@ -348,7 +349,7 @@ class ProvisioningAPI(AuthAPI):
self.log.exception("Failed to disconnect chat")
return self.get_error_response(500, "exception", "Failed to disconnect chat")
else:
asyncio.create_task(coro)
background_task.create(coro)
return web.json_response({}, status=200 if sync else 202)
async def get_user_info(self, request: web.Request) -> web.Response: