1- import json
21import asyncio
3- import inspect
42from functools import partial
3+ import inspect
4+ import json
5+ from typing import Any , Callable , Optional , Type , Union , cast
56from typing_extensions import override
6- from typing import Any , Type , Union , Callable , Optional , cast
77
8+ from githubkit .exception import GraphQLFailed , RequestFailed , RequestTimeout
89from githubkit .webhooks import verify
10+
11+ from nonebot import get_plugin_config
12+ from nonebot .adapters import Adapter as BaseAdapter
913from nonebot .compat import type_validate_python
10- from githubkit .exception import GraphQLFailed , RequestFailed , RequestTimeout
1114from nonebot .drivers import (
1215 URL ,
1316 Driver ,
17+ HTTPServerSetup ,
1418 Request ,
1519 Response ,
1620 ReverseDriver ,
17- HTTPServerSetup ,
1821)
1922
20- from nonebot import get_plugin_config
21- from nonebot .adapters import Adapter as BaseAdapter
22-
2323from . import event
24- from .utils import log
24+ from .bot import Bot , GitHubBot , OAuthBot
25+ from .config import Config , GitHubApp , OAuthApp
2526from .event import Event , events
26- from .bot import Bot , OAuthBot , GitHubBot
27+ from .exception import ActionFailed , ActionTimeout , GraphQLError , NetworkError
2728from .message import Message , MessageSegment
28- from .config import Config , OAuthApp , GitHubApp
29- from .exception import ActionFailed , GraphQLError , NetworkError , ActionTimeout
29+ from .utils import log
3030
3131
3232def import_event_model (event_name : str ) -> Type [Event ]:
@@ -38,6 +38,7 @@ class Adapter(BaseAdapter):
3838 def __init__ (self , driver : Driver , ** kwargs : Any ):
3939 super ().__init__ (driver , ** kwargs )
4040 self .github_config = get_plugin_config (Config )
41+ self .tasks : set ["asyncio.Task" ] = set ()
4142 self ._setup ()
4243
4344 @classmethod
@@ -101,7 +102,9 @@ async def _handle_webhook(
101102
102103 if event := self .payload_to_event (event_id , event_name , payload ):
103104 bot = cast (Bot , self .bots [app .id ])
104- asyncio .create_task (bot .handle_event (event ))
105+ task = asyncio .create_task (bot .handle_event (event ))
106+ task .add_done_callback (self .tasks .discard )
107+ self .tasks .add (task )
105108
106109 return Response (200 , content = "OK" )
107110
0 commit comments