Skip to content

Commit

Permalink
🐛 update lint config and task store
Browse files Browse the repository at this point in the history
  • Loading branch information
yanyongyu authored Oct 24, 2024
1 parent 880ff0d commit bf20eb7
Show file tree
Hide file tree
Showing 4 changed files with 277 additions and 171 deletions.
10 changes: 5 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,23 @@ ci:
autoupdate_commit_msg: ":arrow_up: auto update by pre-commit hooks"
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.6.3
rev: v0.7.0
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
stages: [commit]
stages: [pre-commit]

- repo: https://github.com/pycqa/isort
rev: 5.13.2
hooks:
- id: isort
stages: [commit]
stages: [pre-commit]

- repo: https://github.com/psf/black
rev: 24.8.0
rev: 24.10.0
hooks:
- id: black
stages: [commit]
stages: [pre-commit]

- repo: https://github.com/nonebot/nonemoji
rev: v0.1.4
Expand Down
26 changes: 16 additions & 10 deletions nonebot/adapters/qq/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def __init__(self, driver: Driver, **kwargs: Any):

self.qq_config: Config = Config(**self.config.dict())

self.tasks: list["asyncio.Task"] = []
self.tasks: set["asyncio.Task"] = set()
self.setup()

@classmethod
Expand Down Expand Up @@ -85,7 +85,9 @@ async def startup(self) -> None:
log("DEBUG", f"QQ api base url: <y>{escape_tag(str(api_base))}</y>")

for bot in self.qq_config.qq_bots:
self.tasks.append(asyncio.create_task(self.run_bot(bot)))
task = asyncio.create_task(self.run_bot(bot))
task.add_done_callback(self.tasks.discard)
self.tasks.add(task)

async def shutdown(self) -> None:
for task in self.tasks:
Expand Down Expand Up @@ -123,17 +125,17 @@ async def run_bot(self, bot_info: BotInfo) -> None:

# start connection in single shard mode
if bot_info.shard is not None:
self.tasks.append(
asyncio.create_task(self._forward_ws(bot, ws_url, bot_info.shard))
)
task = asyncio.create_task(self._forward_ws(bot, ws_url, bot_info.shard))
task.add_done_callback(self.tasks.discard)
self.tasks.add(task)
return

# start connection in sharding mode
shards = gateway_info.shards or 1
for i in range(shards):
self.tasks.append(
asyncio.create_task(self._forward_ws(bot, ws_url, (i, shards)))
)
task = asyncio.create_task(self._forward_ws(bot, ws_url, (i, shards)))
task.add_done_callback(self.tasks.discard)
self.tasks.add(task)
# wait for session start concurrency limit
await asyncio.sleep(gateway_info.session_start_limit.max_concurrency or 1)

Expand Down Expand Up @@ -318,7 +320,9 @@ async def _authenticate(
)

if ready_event:
asyncio.create_task(bot.handle_event(ready_event)) # noqa: RUF006
task = asyncio.create_task(bot.handle_event(ready_event))
task.add_done_callback(self.tasks.discard)
self.tasks.add(task)

return True

Expand Down Expand Up @@ -354,7 +358,9 @@ async def _loop(self, bot: Bot, ws: WebSocket):
else:
if isinstance(event, MessageAuditEvent):
audit_result.add_result(event)
asyncio.create_task(bot.handle_event(event)) # noqa: RUF006
task = asyncio.create_task(bot.handle_event(event))
task.add_done_callback(self.tasks.discard)
self.tasks.add(task)
elif isinstance(payload, HeartbeatAck):
log("TRACE", "Heartbeat ACK")
continue
Expand Down
Loading

0 comments on commit bf20eb7

Please sign in to comment.