fix(redis-streams): survive blocking-read timeout on idle streams
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
redis-py raises redis.exceptions.TimeoutError when a blocking XREADGROUP returns no data within block_ms. On idle streams (US market closed → no market:bars / signals:generated / trades:executed) every blocking read times out; the unhandled exception tore down each worker's asyncio.TaskGroup and exited the process, putting signal-generator, trade-executor and learning-engine into CrashLoopBackOff. Catch it and keep polling. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
parent
b4e1c5cd12
commit
5fce576e33
2 changed files with 51 additions and 7 deletions
|
|
@ -5,6 +5,7 @@ import logging
|
|||
from typing import AsyncIterator
|
||||
|
||||
from redis.asyncio import Redis
|
||||
from redis.exceptions import TimeoutError as RedisTimeoutError
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
|
@ -57,13 +58,18 @@ class StreamConsumer:
|
|||
"""
|
||||
await self.ensure_group()
|
||||
while True:
|
||||
messages = await self.redis.xreadgroup(
|
||||
self.group,
|
||||
self.consumer,
|
||||
{self.stream: ">"},
|
||||
count=batch_size,
|
||||
block=block_ms,
|
||||
)
|
||||
try:
|
||||
messages = await self.redis.xreadgroup(
|
||||
self.group,
|
||||
self.consumer,
|
||||
{self.stream: ">"},
|
||||
count=batch_size,
|
||||
block=block_ms,
|
||||
)
|
||||
except RedisTimeoutError:
|
||||
# redis-py raises this when a blocking read returns no data
|
||||
# within block_ms (idle stream). Expected — keep polling.
|
||||
continue
|
||||
for _stream_name, entries in messages:
|
||||
for msg_id, fields in entries:
|
||||
data = json.loads(fields[b"data"])
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue