-
-
Notifications
You must be signed in to change notification settings - Fork 238
Optimize the opera log storage logic through queue #750
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 4 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
c4db509
✨ feat: 操作日志中间件添加批量插入功能
1b1b0f6
Delete GEMINI.md
IAseven 174052a
🌈 style: 修复格式化错误
9656a70
🐞 fix: 通过asyncio.wait_for兼容py3.10中asyncio.timeout不存在
6b91abc
🦄 refactor: 重新组织操作日志批量插入代码逻辑
14fac97
优化代码实现
wu-clan d0c1208
恢复默认配置
wu-clan cd303c8
恢复默认 .gitignore 文件
wu-clan e906361
更新队列批处理逻辑
wu-clan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,3 +7,6 @@ venv/ | |
| .python-version | ||
| .ruff_cache/ | ||
| .pytest_cache/ | ||
| .env | ||
| docker-compose-dev.yml | ||
| GEMINI.md | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| #!/usr/bin/env python3 | ||
| # -*- coding: utf-8 -*- | ||
| import asyncio | ||
|
|
||
| from asyncio import Queue | ||
| from typing import List | ||
|
|
||
| # 操作日志队列 | ||
| opera_log_queue: Queue = Queue(maxsize=100000) | ||
|
|
||
|
|
||
| async def get_many_from_queue(queue: Queue, max_items: int, timeout: float) -> List: | ||
| """ | ||
| 在指定的超时时间内,从异步队列中批量获取项目。 | ||
| 此函数会尝试从给定的 `asyncio.Queue` 中获取最多 `max_items` 个项目。 | ||
| 它会为整个获取过程设置一个总的 `timeout` 秒数的超时限制。如果在超时 | ||
| 时间内未能收集到 `max_items` 个项目,函数将返回当前已成功获取的所有项目。 | ||
| Args: | ||
| queue: 用于获取项目的 `asyncio.Queue` 队列。 | ||
| max_items: 希望从队列中获取的最大项目数量。 | ||
| timeout: 总的等待超时时间(秒)。 | ||
| Returns: | ||
| 一个从队列中获取到的项目列表。如果发生超时, | ||
| 列表中的项目数量可能会少于 `max_items`。 | ||
| """ | ||
wu-clan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| results = [] | ||
|
|
||
| async def collector(): | ||
| while len(results) < max_items: | ||
| item = await queue.get() | ||
| results.append(item) | ||
|
|
||
| try: | ||
| await asyncio.wait_for(collector(), timeout=timeout) | ||
| except asyncio.TimeoutError: | ||
| pass # 超时后返回已有的 items | ||
| return results | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.