-
-
Notifications
You must be signed in to change notification settings - Fork 205
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
Open
IAseven
wants to merge
5
commits into
fastapi-practices:master
Choose a base branch
from
IAseven:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+89
−2
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
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,38 @@ | ||
#!/usr/bin/env python3 | ||
# -*- coding: utf-8 -*- | ||
import asyncio | ||
|
||
from asyncio import Queue | ||
from typing import List | ||
|
||
|
||
async def get_many_from_queue(queue: Queue, max_items: int, timeout: float) -> List: | ||
""" | ||
在指定的超时时间内,从异步队列中批量获取项目。 | ||
|
||
此函数会尝试从给定的 ``asyncio.Queue`` 中获取最多 ``max_items`` 个项目。 | ||
它会为整个获取过程设置一个总的 ``timeout`` 秒数的超时限制。 | ||
如果在超时时间内未能收集到 ``max_items`` 个项目, | ||
函数将返回当前已成功获取的所有项目。 | ||
|
||
:param queue: 用于获取项目的 ``asyncio.Queue`` 队列。 | ||
:type queue: asyncio.Queue | ||
:param max_items: 希望从队列中获取的最大项目数量。 | ||
:type max_items: int | ||
:param timeout: 总的等待超时时间(秒)。 | ||
:type timeout: float | ||
:return: 一个从队列中获取到的项目列表。如果发生超时,列表中的项目数量可能会少于 ``max_items``。 | ||
:rtype: List | ||
""" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 让我们使用 reStructuredText 风格文档 |
||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这些内容看起来似乎没有实质用处
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
是的,这个是我本地测试的配置文件,为了防止提交到远程仓库添加的忽略配置