Skip to content
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

[backend] make sure redis consumer group exist #1684

Merged
merged 2 commits into from
May 16, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions ymir/backend/src/ymir_app/app/libs/redis_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ async def init_group_and_stream(self) -> None:
if not exists:
logger.info("init redis stream and consumer group")
await self._conn.xgroup_create(name=self.stream_name, groupname=self.group_name, mkstream=True)
else:
groups = await self._conn.xinfo_groups(self.stream_name)
if not any(group["name"] == self.group_name for group in groups):
logger.info("init consumer group on existing stream")
# set id = '0' to make sure this new consumer group will catch up existing messages in stream
await self._conn.xgroup_create(name=self.stream_name, groupname=self.group_name, id="0")

async def connect(self) -> None:
self._conn = await redis.from_url(self.redis_uri, decode_responses=True)
Expand Down