fix(event_bus): 修复异常处理 + 补充 fakeredis dev 依赖
- _ensure_groups: 非 BUSYGROUP 异常改为 raise - read_new: 移除静默吞异常,让调用方决定如何处理 - pyproject.toml dev: 新增 fakeredis>=2.0 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
+1
-1
@@ -16,7 +16,7 @@ dependencies = [
|
||||
]
|
||||
|
||||
[project.optional-dependencies]
|
||||
dev = ["pytest>=8.0", "pytest-asyncio>=0.23"]
|
||||
dev = ["pytest>=8.0", "pytest-asyncio>=0.23", "fakeredis>=2.0"]
|
||||
|
||||
[tool.setuptools.packages.find]
|
||||
where = ["src"]
|
||||
|
||||
@@ -46,8 +46,10 @@ class EventBus:
|
||||
try:
|
||||
self._r.xgroup_create(self._stream, group, id="0", mkstream=True)
|
||||
except Exception as e:
|
||||
if "BUSYGROUP" not in str(e):
|
||||
logger.warning("xgroup_create %s: %s", group, e)
|
||||
if "BUSYGROUP" in str(e):
|
||||
logger.debug("consumer group %s 已存在", group)
|
||||
else:
|
||||
raise
|
||||
|
||||
def publish(self, event: AgentEvent) -> str:
|
||||
data = {
|
||||
@@ -69,16 +71,12 @@ class EventBus:
|
||||
count: int = 10,
|
||||
block_ms: int = 0,
|
||||
) -> list[AgentEvent]:
|
||||
try:
|
||||
results = self._r.xreadgroup(
|
||||
consumer_group, consumer_name,
|
||||
{self._stream: ">"},
|
||||
count=count,
|
||||
block=block_ms or None,
|
||||
)
|
||||
except Exception as e:
|
||||
logger.warning("EventBus read_new 失败: %s", e)
|
||||
return []
|
||||
results = self._r.xreadgroup(
|
||||
consumer_group, consumer_name,
|
||||
{self._stream: ">"},
|
||||
count=count,
|
||||
block=block_ms or None,
|
||||
)
|
||||
events: list[AgentEvent] = []
|
||||
if results:
|
||||
for _stream, messages in results:
|
||||
|
||||
Reference in New Issue
Block a user