mirror of
https://github.com/aiogram/aiogram.git
synced 2026-04-08 16:37:47 +00:00
Preserve update handling task pointers, backport of #1328
This commit is contained in:
parent
67382553e5
commit
6f1711e0bd
2 changed files with 8 additions and 2 deletions
|
|
@ -95,6 +95,7 @@ class Dispatcher(Router):
|
|||
self._running_lock = Lock()
|
||||
self._stop_signal: Optional[Event] = None
|
||||
self._stopped_signal: Optional[Event] = None
|
||||
self._handle_update_tasks = set()
|
||||
|
||||
def __getitem__(self, item: str) -> Any:
|
||||
return self.workflow_data[item]
|
||||
|
|
@ -349,7 +350,9 @@ class Dispatcher(Router):
|
|||
):
|
||||
handle_update = self._process_update(bot=bot, update=update, **kwargs)
|
||||
if handle_as_tasks:
|
||||
asyncio.create_task(handle_update)
|
||||
handle_update_task = asyncio.create_task(handle_update)
|
||||
self._handle_update_tasks.add(handle_update_task)
|
||||
handle_update_task.add_done_callback(self._handle_update_tasks.discard)
|
||||
else:
|
||||
await handle_update
|
||||
finally:
|
||||
|
|
|
|||
|
|
@ -98,6 +98,7 @@ class BaseRequestHandler(ABC):
|
|||
self.dispatcher = dispatcher
|
||||
self.handle_in_background = handle_in_background
|
||||
self.data = data
|
||||
self._background_feed_update_tasks = set()
|
||||
|
||||
def register(self, app: Application, /, path: str, **kwargs: Any) -> None:
|
||||
"""
|
||||
|
|
@ -139,11 +140,13 @@ class BaseRequestHandler(ABC):
|
|||
await self.dispatcher.silent_call_request(bot=bot, result=result)
|
||||
|
||||
async def _handle_request_background(self, bot: Bot, request: web.Request) -> web.Response:
|
||||
asyncio.create_task(
|
||||
feed_update_task = asyncio.create_task(
|
||||
self._background_feed_update(
|
||||
bot=bot, update=await request.json(loads=bot.session.json_loads)
|
||||
)
|
||||
)
|
||||
self._background_feed_update_tasks.add(feed_update_task)
|
||||
feed_update_task.add_done_callback(self._background_feed_update_tasks.discard)
|
||||
return web.json_response({}, dumps=bot.session.json_dumps)
|
||||
|
||||
def _build_response_writer(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue