Conversation
There was a problem hiding this comment.
Summary of Changes
Hello @youyeon11, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
이 PR은 Redis 메시지 구독 및 Task 발행 과정에서 발생하던 오류를 수정하고, 시스템 간의 데이터 일관성을 확보하는 데 중점을 둡니다. 특히, Spring 서버와의 연동을 위해 Redis 메시지 형식을 표준화하고, 데이터 처리 로직의 안정성을 개선하여 전반적인 시스템의 신뢰도를 향상시켰습니다.
Highlights
- Redis Task 오류 수정: Redis 구독 메시지를 제대로 인식하지 못해 Task 발행이 실패하던 문제를 해결했습니다.
- 데이터 직렬화 및 필드명 통일: Spring 서버와의 통신을 위해 Redis에 발행하는 메시지의 필드명을 camelCase로 통일하고, 직렬화 문제를 해결하기 위한 전처리 함수를 추가했습니다.
- 이미지 처리 로직 개선: S3에서 다운로드한 파일 스트림 처리와
asyncio.to_thread인자 전달 방식을 수정하여 이미지 처리의 안정성을 높였습니다. - Redis 클라이언트 기능 확장: Redis Stream 메시지 처리를 위한
_to_scalar,_sanitize_fields_for_xadd유틸리티 함수와xautoclaim기능을 추가하여 견고성을 강화했습니다.
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.
| Feature | Command | Description |
|---|---|---|
| Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
| Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
| Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
| Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
🤖 Gemini 코드 리뷰 결과1. 주요 변경 사항 요약 및 의도 파악이 PR은 Redis Task 처리 과정에서 발생하는 오류를 수정하고 Spring Server와의 데이터 교환 호환성을 개선하는 것을 목표로 합니다. 구체적으로, Redis 메시지 발행/구독 과정에서 필드 불일치 문제를 해결하고, Python의 snake_case와 Spring의 camelCase 차이를 해결하기 위해 필드 이름을 camelCase로 통일했습니다. 또한, 비동기 처리를 위해 2. 코드 품질 및 가독성
3. 잠재적 버그 및 엣지 케이스
4. 성능 및 효율성
5. 보안 및 아키텍처
전반적으로 잘 작성된 PR입니다. 위에 언급된 몇 가지 사소한 수정 사항과 제안 사항을 반영한다면 더욱 견고하고 유지보수하기 쉬운 코드가 될 것입니다. 특히, 에러 핸들링 부분을 보완하고, |
There was a problem hiding this comment.
Code Review
이 PR은 Redis 구독 메시지를 제대로 인식하지 못하는 문제를 해결하고, Spring 서버와의 호환성을 위해 데이터 구조를 변경하는 등 중요한 수정을 포함하고 있습니다. 전반적으로 코드의 안정성과 호환성을 높이는 좋은 변경이지만, 몇 가지 개선할 점이 보입니다. 특히 Redis 스트림 메시지 타입 불일치와 작업 처리 로직의 버그와 같은 심각한 문제가 있으며, 코드 중복 및 타입 안정성 문제도 발견되었습니다. 아래에 자세한 리뷰를 남겼으니 확인 부탁드립니다.
| settings.STREAM_JOB, | ||
| {"json": job.model_dump_json()}, | ||
| { | ||
| "type": "image_results", |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
app/worker/worker.py
Outdated
| data = json.loads(payload_str) | ||
| print(f"Job received id={msg_id} correlationId={correlation_id} payload={data}") | ||
|
|
||
| job = data |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
| """ | ||
| Redis Stream에 정의한 유효한 형식 메시지를 위한 전처리 함수 | ||
| """ | ||
| def _to_scalr(v): | ||
| # XADD 허용 타입: str, bytes, int, float | ||
| if isinstance(v, (str, bytes, int, float)): | ||
| return v | ||
| # 그 외는 JSON str | ||
| return json.dumps(v, ensure_ascii=False) | ||
|
|
||
| """ | ||
| Decoding | ||
| """ | ||
| def _decode(b): | ||
| if isinstance(b, (bytes, bytearray)): | ||
| return b.decode() | ||
| else: | ||
| return b | ||
|
|
||
|
|
||
| def _sanitize_fields_for_xadd(fields: dict) -> dict: | ||
| # 정제 | ||
| cleaned = {} | ||
| for k, v in fields.items(): | ||
| k = _decode(k) | ||
| if isinstance(v, (bytes, bytearray)): | ||
| try: | ||
| v = v.decode() | ||
| except Exception: | ||
| pass | ||
| else: | ||
| v = _to_scalr(v) | ||
| cleaned[k] = v | ||
| return cleaned |
| print("분석 결과 발행 시작...") | ||
| entry_id = await redis_client.xadd( | ||
| settings.STREAM_JOB, | ||
| {"json": job.model_dump_json()}, | ||
| { | ||
| "type": "image_results", | ||
| "payload": payload, | ||
| "correlationId": correlationId, | ||
| }, | ||
| maxlen=10_000, | ||
| approximate=True, | ||
| ) | ||
|
|
||
| return {"job_id": correlation_id} No newline at end of file | ||
| print("분석 결과 발행 완료...") |
| try: | ||
| v = v.decode() | ||
| except Exception: | ||
| pass |
There was a problem hiding this comment.
| task.add_done_callback(lambda t: asyncio.create_task( | ||
| self.redis_client.xack_and_del(settings.STREAM_JOB, settings.GROUP_NAME, msg_id) | ||
| if not t.exception() else | ||
| self.redis_client.xadd(f"{settings.STREAM_JOB}:DLQ", | ||
| {"id": msg_id, "error": str(t.exception()), **fields}) | ||
| )) |
📌 작업 목적
🗂 작업 유형
🔨 주요 작업 내용
tasks.pyworkers.pyjob.pytasks.py🧪 테스트 결과
📎 관련 이슈
💬 논의 및 고민한 점