Skip to content

DEPLOY v1.0.0#23

Merged
youyeon11 merged 36 commits intomainfrom
develop
Sep 7, 2025
Merged

DEPLOY v1.0.0#23
youyeon11 merged 36 commits intomainfrom
develop

Conversation

@youyeon11
Copy link
Contributor

youyeon11 and others added 30 commits August 29, 2025 00:18
[FEATURE] Docker ๊ธฐ๋ฐ˜ Blue/Gren ๋ฌด์ค‘๋‹จ๋ฐฐํฌ
[FEATURE] S3 ์ด๋ฏธ์ง€ ์ฝ๊ธฐ ๊ตฌํ˜„
[FIX] Redis Task ์˜ค๋ฅ˜ ์ˆ˜์ •
Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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์€ v1.0.0 ๋ฐฐํฌ๋ฅผ ์œ„ํ•œ ๊ฒƒ์œผ๋กœ, ๊ธฐ์กด ์ž‘์—…๋“ค์„ ํ†ตํ•ฉํ•˜๊ณ  ์ƒˆ๋กœ์šด ๊ธฐ๋Šฅ(์ž„์‚ฐ๋ถ€ ์•ฝ ์•ˆ์ „์„ฑ ๊ฒ€์‚ฌ)์„ ์ถ”๊ฐ€ํ•˜๋ฉฐ, ์‹œ์Šคํ…œ ์•„ํ‚คํ…์ฒ˜๋ฅผ ๊ฐœ์„ ํ•˜๊ณ  ๋ฐฐํฌ ํ”„๋กœ์„ธ์Šค๋ฅผ ์ž๋™ํ™”ํ•ฉ๋‹ˆ๋‹ค. ์ฃผ์š” ๋ณ€๊ฒฝ ์‚ฌํ•ญ์€ Redis ์ŠคํŠธ๋ฆผ ์ฒ˜๋ฆฌ์˜ ๊ฒฌ๊ณ ์„ฑ ๊ฐ•ํ™”, OpenAI ์„œ๋น„์Šค ํ†ตํ•ฉ, ๊ทธ๋ฆฌ๊ณ  ๋ธ”๋ฃจ/๊ทธ๋ฆฐ ๋ฐฐํฌ ์‹œ์Šคํ…œ ๋„์ž…์ž…๋‹ˆ๋‹ค.

Highlights

  • ์ƒˆ๋กœ์šด ๋ฐฐํฌ ์‹œ์Šคํ…œ ๋„์ž…: Docker Compose์™€ Nginx๋ฅผ ํ™œ์šฉํ•œ ๋ธ”๋ฃจ/๊ทธ๋ฆฐ ๋ฐฐํฌ ์Šคํฌ๋ฆฝํŠธ ๋ฐ ์„ค์ • ํŒŒ์ผ์ด ์ถ”๊ฐ€๋˜์–ด ์•ˆ์ •์ ์ธ ์„œ๋น„์Šค ์—…๋ฐ์ดํŠธ๊ฐ€ ๊ฐ€๋Šฅํ•ด์กŒ์Šต๋‹ˆ๋‹ค.
  • Redis ์ŠคํŠธ๋ฆผ ์ฒ˜๋ฆฌ ๋กœ์ง ๊ฐœ์„ : Redis ํด๋ผ์ด์–ธํŠธ๊ฐ€ ์žฌ๊ตฌํ˜„๋˜์–ด ์ŠคํŠธ๋ฆผ ๋ฉ”์‹œ์ง€ ๋ฐœํ–‰ ๋ฐ ์†Œ๋น„ ๋กœ์ง์ด ๋”์šฑ ๊ฒฌ๊ณ ํ•ด์กŒ์œผ๋ฉฐ, DLQ(Dead Letter Queue) ์ฒ˜๋ฆฌ๊ฐ€ ๊ฐ•ํ™”๋˜์—ˆ์Šต๋‹ˆ๋‹ค.
  • OpenAI ๊ธฐ๋ฐ˜ ์ž„์‚ฐ๋ถ€ ์•ฝ ์•ˆ์ „์„ฑ ๊ฒ€์‚ฌ ๊ธฐ๋Šฅ ์ถ”๊ฐ€: ์•ฝ ์ด๋ฏธ์ง€ ๋ถ„์„ ๊ฒฐ๊ณผ์— ๋”ฐ๋ผ OpenAI API๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ž„์‚ฐ๋ถ€ ๋ณต์šฉ ์•ˆ์ „์„ฑ ์ •๋ณด๋ฅผ ์ œ๊ณตํ•˜๋Š” ์ƒˆ๋กœ์šด ์„œ๋น„์Šค๊ฐ€ ํ†ตํ•ฉ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.
  • ๋ฐ์ดํ„ฐ ๋ชจ๋ธ ๋ฐ ์„œ๋น„์Šค ์ธํ„ฐํŽ˜์ด์Šค ๋ณ€๊ฒฝ: JobRequest, JobResult, ImageJob ์Šคํ‚ค๋งˆ๊ฐ€ ์—…๋ฐ์ดํŠธ๋˜์—ˆ๊ณ , S3 ์„œ๋น„์Šค๊ฐ€ ํŒŒ์ผ์„ ์ง์ ‘ ์ €์žฅํ•˜๋Š” ๋Œ€์‹  BytesIO ๊ฐ์ฒด๋ฅผ ๋ฐ˜ํ™˜ํ•˜๋„๋ก ๋ณ€๊ฒฝ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.
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

  1. 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. โ†ฉ

@youyeon11
Copy link
Contributor Author

๐Ÿค– Gemini ์ฝ”๋“œ ๋ฆฌ๋ทฐ ๊ฒฐ๊ณผ

1. ์ฃผ์š” ๋ณ€๊ฒฝ ์‚ฌํ•ญ ์š”์•ฝ ๋ฐ ์˜๋„ ํŒŒ์•…

์ด PR์€ v1.0.0 ๋ฐฐํฌ๋ฅผ ์œ„ํ•œ ๊ฒƒ์œผ๋กœ, #22, #21, #19, #18 ์ด์Šˆ์™€ ๊ด€๋ จ๋œ ์ž‘์—… ๋‚ด์šฉ์„ ํฌํ•จํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. ๋ณ€๊ฒฝ๋œ ํŒŒ์ผ ๋ชฉ๋ก์„ ๋ณด๋ฉด, ๋ฐฐํฌ ์Šคํฌ๋ฆฝํŠธ, Docker Compose ์„ค์ •, Nginx ์„ค์ •, ์˜์กด์„ฑ ํŒŒ์ผ, API ์—”๋“œํฌ์ธํŠธ, ์„œ๋น„์Šค ๋กœ์ง, ๊ทธ๋ฆฌ๊ณ  ํ…Œ์ŠคํŠธ ์ฝ”๋“œ๊นŒ์ง€ ๊ด‘๋ฒ”์œ„ํ•˜๊ฒŒ ์ˆ˜์ •๋œ ๊ฒƒ์œผ๋กœ ๋ณด์ž…๋‹ˆ๋‹ค. ํ•ต์‹ฌ์ ์ธ ๋ณ€๊ฒฝ ์‚ฌํ•ญ์€ ์ด๋ฏธ์ง€ ๋ถ„์„ ์ž‘์—…์„ Redis Stream์„ ํ†ตํ•ด ๋น„๋™๊ธฐ์ ์œผ๋กœ ์ฒ˜๋ฆฌํ•˜๊ณ , OpenAI API๋ฅผ ํ™œ์šฉํ•˜์—ฌ ์ž„์‚ฐ๋ถ€ ๋ณต์šฉ ์•ˆ์ „์„ฑ ์ •๋ณด๋ฅผ ์ œ๊ณตํ•˜๋Š” ๊ธฐ๋Šฅ ์ถ”๊ฐ€, ๊ทธ๋ฆฌ๊ณ  ๋ฐฐํฌ ์ž๋™ํ™”๋ฅผ ์œ„ํ•œ CI/CD ํŒŒ์ดํ”„๋ผ์ธ ๊ตฌ์ถ•์œผ๋กœ ์š”์•ฝ๋  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

2. ์ฝ”๋“œ ํ’ˆ์งˆ ๋ฐ ๊ฐ€๋…์„ฑ

  • ์ฝ”๋“œ ์Šคํƒ€์ผ: ์ „๋ฐ˜์ ์œผ๋กœ PEP 8 ๊ทœ์น™์„ ์ž˜ ์ค€์ˆ˜ํ•˜๊ณ  ์žˆ์œผ๋‚˜, ์ผ๋ถ€ ํŒŒ์ผ์—์„œ \ No newline at end of file ๋ฉ”์‹œ์ง€๊ฐ€ ๋‚˜ํƒ€๋‚˜๋Š” ๊ฒƒ์œผ๋กœ ๋ณด์•„ ํŒŒ์ผ ๋์— newline์ด ์—†๋Š” ๊ฒฝ์šฐ๊ฐ€ ์žˆ๋Š” ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค. ๊ฐ ํŒŒ์ผ์˜ ๋งˆ์ง€๋ง‰์— newline์„ ์ถ”๊ฐ€ํ•˜๋Š” ๊ฒƒ์ด ์ข‹๊ฒ ์Šต๋‹ˆ๋‹ค.
  • ๋ณ€์ˆ˜/ํ•จ์ˆ˜๋ช…: correlation_id์—์„œ correlationId ๋กœ ๋ณ€๊ฒฝ๋˜๋Š” ๋“ฑ ์นด๋ฉœ์ผ€์ด์Šค, ์Šค๋„ค์ดํฌ์ผ€์ด์Šค๊ฐ€ ํ˜ผ์šฉ๋˜์–ด ์‚ฌ์šฉ๋˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. ํ”„๋กœ์ ํŠธ ์ „์ฒด์—์„œ ์ผ๊ด€๋œ ๋„ค์ด๋ฐ ์ปจ๋ฒค์…˜(์˜ˆ: ์นด๋ฉœ์ผ€์ด์Šค)์„ ์ ์šฉํ•˜์—ฌ ์ฝ”๋“œ์˜ ๊ฐ€๋…์„ฑ์„ ๋†’์ด๋Š” ๊ฒƒ์ด ์ข‹๊ฒ ์Šต๋‹ˆ๋‹ค. ask_chatgpt_about_pregnancy_safety์™€ ๊ฐ™์ด ๊ธด ํ•จ์ˆ˜ ์ด๋ฆ„์€ check_pregnancy_safety์ฒ˜๋Ÿผ ๋” ๊ฐ„๊ฒฐํ•˜๊ฒŒ ํ‘œํ˜„ํ•  ์ˆ˜ ์žˆ์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.
  • ์ฃผ์„/๋ฌธ์„œํ™”: predictions.py, schemas.py, tasks.py, worker.py ๋“ฑ์˜ ํŒŒ์ผ์— ์ฃผ์š” ๊ธฐ๋Šฅ์— ๋Œ€ํ•œ ์„ค๋ช…์ด ์ฃผ์„์œผ๋กœ ์ž˜ ์ž‘์„ฑ๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค. ํ•˜์ง€๋งŒ, openai_service.py์˜ PregnancySafetyChecker ํด๋ž˜์Šค์™€ ๊ฐ™์ด ํ•ต์‹ฌ ๋กœ์ง์— ๋Œ€ํ•œ ๋ฌธ์„œํ™”๋Š” ๋ถ€์กฑํ•ด ๋ณด์ž…๋‹ˆ๋‹ค. ํด๋ž˜์Šค์™€ ๋ฉ”์„œ๋“œ์˜ ์—ญํ• , ๋งค๊ฐœ๋ณ€์ˆ˜ ๋ฐ ๋ฐ˜ํ™˜ ๊ฐ’์— ๋Œ€ํ•œ ์„ค๋ช…์„ ์ถ”๊ฐ€ํ•˜์—ฌ ์ฝ”๋“œ์˜ ์ดํ•ด๋„๋ฅผ ๋†’์ด๋Š” ๊ฒƒ์ด ์ข‹๊ฒ ์Šต๋‹ˆ๋‹ค.
  • ์ค‘๋ณต ์ฝ”๋“œ: ํ˜„์žฌ ์ œ๊ณต๋œ ์ฝ”๋“œ ์Šค๋‹ˆํŽซ๋งŒ์œผ๋กœ๋Š” ์ค‘๋ณต ์ฝ”๋“œ๋ฅผ ์ •ํ™•ํžˆ ํŒŒ์•…ํ•˜๊ธฐ ์–ด๋ ต์Šต๋‹ˆ๋‹ค. ์ „์ฒด ์ฝ”๋“œ๋ฒ ์ด์Šค๋ฅผ ๊ฒ€ํ† ํ•˜์—ฌ ์ค‘๋ณต๋œ ๋กœ์ง์ด ์žˆ๋‹ค๋ฉด ์žฌ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•œ ํ•จ์ˆ˜๋‚˜ ํด๋ž˜์Šค๋กœ ์ถ”์ถœํ•˜๋Š” ๊ฒƒ์„ ๊ณ ๋ คํ•ด ๋ณด์„ธ์š”.

3. ์ž ์žฌ์  ๋ฒ„๊ทธ ๋ฐ ์—ฃ์ง€ ์ผ€์ด์Šค

  • ๋…ผ๋ฆฌ์  ์˜ค๋ฅ˜: openai_service.py์—์„œ json.loads() ํ˜ธ์ถœ ์‹œ ๋ฐœ์ƒํ•  ์ˆ˜ ์žˆ๋Š” JSONDecodeError ์˜ˆ์™ธ ์ฒ˜๋ฆฌ ๋กœ์ง์ด ๋‹ค์†Œ ๋ณต์žกํ•ฉ๋‹ˆ๋‹ค. OpenAI API์˜ ์‘๋‹ต ํ˜•์‹์ด ๋ณ€๊ฒฝ๋  ๊ฒฝ์šฐ ์ด ๋กœ์ง์ด ์ œ๋Œ€๋กœ ๋™์ž‘ํ•˜์ง€ ์•Š์„ ๊ฐ€๋Šฅ์„ฑ์ด ์žˆ์Šต๋‹ˆ๋‹ค. ๋ณด๋‹ค ๊ฐ„๊ฒฐํ•˜๊ณ  ์•ˆ์ •์ ์ธ ์˜ˆ์™ธ ์ฒ˜๋ฆฌ ๋ฐฉ์‹์„ ๊ณ ๋ คํ•ด ๋ณด์„ธ์š”.
  • ๊ฒฝ์Ÿ ์ƒํƒœ (Race Condition): ํ˜„์žฌ ์ฝ”๋“œ์—์„œ ๋ฉ€ํ‹ฐ์“ฐ๋ ˆ๋“œ/๋น„๋™๊ธฐ ํ™˜๊ฒฝ์—์„œ ๋ฐœ์ƒํ•  ์ˆ˜ ์žˆ๋Š” ์ž ์žฌ์ ์ธ ๊ฒฝ์Ÿ ์ƒํƒœ ๋ฌธ์ œ๋Š” ๋ณด์ด์ง€ ์•Š์Šต๋‹ˆ๋‹ค. ํ•˜์ง€๋งŒ, Redis Stream์„ ์‚ฌ์šฉํ•˜๋Š” ๋ถ€๋ถ„์—์„œ ๋™์‹œ์„ฑ ๋ฌธ์ œ๊ฐ€ ๋ฐœ์ƒํ•  ๊ฐ€๋Šฅ์„ฑ์„ ํ•ญ์ƒ ์—ผ๋‘์— ๋‘๊ณ  ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.
  • ์—๋Ÿฌ ํ•ธ๋“ค๋ง: tasks.py์˜ process_image_scan ํ•จ์ˆ˜์—์„œ ๋ฐœ์ƒํ•˜๋Š” ์˜ˆ์™ธ๋ฅผ ํฌ๊ด„์ ์ธ Exception์œผ๋กœ ์ฒ˜๋ฆฌํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. ์ข€ ๋” ๊ตฌ์ฒด์ ์ธ ์˜ˆ์™ธ ํƒ€์ž…(์˜ˆ: requests.exceptions.RequestException, IOError)์œผ๋กœ ์ฒ˜๋ฆฌํ•˜์—ฌ ์˜ˆ์™ธ ์ƒํ™ฉ์— ๋Œ€ํ•œ ์„ธ๋ถ„ํ™”๋œ ๋Œ€์‘์ด ๊ฐ€๋Šฅํ•˜๋„๋ก ๊ฐœ์„ ํ•˜๋Š” ๊ฒƒ์ด ์ข‹๊ฒ ์Šต๋‹ˆ๋‹ค.

4. ์„ฑ๋Šฅ ๋ฐ ํšจ์œจ์„ฑ

  • ์‹œ๊ฐ„ ๋ณต์žก๋„: ์ œ๊ณต๋œ ์ฝ”๋“œ๋งŒ์œผ๋กœ๋Š” ์•Œ๊ณ ๋ฆฌ์ฆ˜์˜ ์‹œ๊ฐ„ ๋ณต์žก๋„๋ฅผ ์ •ํ™•ํžˆ ๋ถ„์„ํ•˜๊ธฐ ์–ด๋ ต์Šต๋‹ˆ๋‹ค. ์ „์ฒด ์ฝ”๋“œ๋ฒ ์ด์Šค๋ฅผ ๊ฒ€ํ† ํ•˜๊ณ , ์„ฑ๋Šฅ ํ”„๋กœํŒŒ์ผ๋ง ๋„๊ตฌ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋ณ‘๋ชฉ ํ˜„์ƒ์ด ๋ฐœ์ƒํ•˜๋Š” ๋ถ€๋ถ„์„ ํŒŒ์•…ํ•˜์—ฌ ์ตœ์ ํ™”๋ฅผ ์ง„ํ–‰ํ•˜๋Š” ๊ฒƒ์ด ์ข‹๊ฒ ์Šต๋‹ˆ๋‹ค.
  • ์ž์› ์‚ฌ์šฉ: tasks.py์—์„œ ์ด๋ฏธ์ง€ ํŒŒ์ผ์„ /tmp ๋””๋ ‰ํ„ฐ๋ฆฌ์— ์ €์žฅํ•˜๊ณ  ์ฒ˜๋ฆฌํ•œ ํ›„ ์‚ญ์ œํ•˜๋Š” ๋กœ์ง์ด ์žˆ์Šต๋‹ˆ๋‹ค. ๋Œ€์šฉ๋Ÿ‰ ์ด๋ฏธ์ง€ ํŒŒ์ผ์„ ์ฒ˜๋ฆฌํ•  ๊ฒฝ์šฐ ๋””์Šคํฌ I/O ๋ถ€ํ•˜๊ฐ€ ๋ฐœ์ƒํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์ด๋ฏธ์ง€ ํŒŒ์ผ์„ ๋ฉ”๋ชจ๋ฆฌ์—์„œ ์ง์ ‘ ์ฒ˜๋ฆฌํ•˜๋Š” ๋ฐฉ์‹์„ ๊ณ ๋ คํ•ด ๋ณด์„ธ์š”.
  • ์ตœ์ ํ™” ์ œ์•ˆ: worker.py ์—์„œ Redis Stream์„ polling ํ•˜๋Š” ๋ฐฉ์‹ ๋Œ€์‹ , pub/sub ๋ฐฉ์‹์„ ์‚ฌ์šฉํ•˜์—ฌ ๋ฉ”์‹œ์ง€๊ฐ€ ๋„์ฐฉํ•˜๋Š” ์ฆ‰์‹œ ์ฒ˜๋ฆฌํ•˜๋Š” ๋ฐฉ์‹์„ ๊ณ ๋ คํ•ด ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

5. ๋ณด์•ˆ ๋ฐ ์•„ํ‚คํ…์ฒ˜

  • ๋ณด์•ˆ ์ทจ์•ฝ์ : .env ํŒŒ์ผ์„ ํ†ตํ•ด ํ™˜๊ฒฝ ๋ณ€์ˆ˜๋ฅผ ๊ด€๋ฆฌํ•˜๊ณ  ์žˆ๋Š”๋ฐ, .env ํŒŒ์ผ์ด Git ์ €์žฅ์†Œ์— ํฌํ•จ๋˜์ง€ ์•Š๋„๋ก .gitignore์— ์ถ”๊ฐ€ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. ๋˜ํ•œ, ์™ธ๋ถ€ ์„œ๋น„์Šค(OpenAI API, S3)์™€ ํ†ต์‹ ํ•˜๋Š” ๋ถ€๋ถ„์—์„œ ์ธ์ฆ ์ •๋ณด๊ฐ€ ์•ˆ์ „ํ•˜๊ฒŒ ๊ด€๋ฆฌ๋˜๊ณ  ์žˆ๋Š”์ง€ ํ™•์ธํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.
  • ์•„ํ‚คํ…์ฒ˜ ์ ํ•ฉ์„ฑ: Redis Stream์„ ์‚ฌ์šฉํ•˜์—ฌ ๋น„๋™๊ธฐ ์ž‘์—… ํ๋ฅผ ๊ตฌํ˜„ํ•œ ๊ฒƒ์€ ์ข‹์€ ์„ ํƒ์œผ๋กœ ๋ณด์ž…๋‹ˆ๋‹ค. ๋‹ค๋งŒ, ์ „์ฒด ์‹œ์Šคํ…œ ์•„ํ‚คํ…์ฒ˜์— ๋Œ€ํ•œ ์ •๋ณด๊ฐ€ ๋ถ€์กฑํ•˜์—ฌ ์ ํ•ฉ์„ฑ์„ ์™„์ „ํžˆ ํŒ๋‹จํ•˜๊ธฐ๋Š” ์–ด๋ ต์Šต๋‹ˆ๋‹ค.
  • ํ™•์žฅ์„ฑ: ํ˜„์žฌ ๊ตฌํ˜„๋œ Worker๋Š” ๋‹จ์ผ ์ธ์Šคํ„ด์Šค๋กœ ๋™์ž‘ํ•˜๋Š” ๊ฒƒ์œผ๋กœ ๋ณด์ž…๋‹ˆ๋‹ค. ํ–ฅํ›„ ์ž‘์—…๋Ÿ‰ ์ฆ๊ฐ€์— ๋Œ€๋น„ํ•˜์—ฌ ์—ฌ๋Ÿฌ ๊ฐœ์˜ Worker๋ฅผ ์‹คํ–‰ํ•˜๊ณ , ์ž‘์—…์„ ๋ถ„์‚ฐ ์ฒ˜๋ฆฌํ•  ์ˆ˜ ์žˆ๋„๋ก ์„ค๊ณ„ํ•˜๋Š” ๊ฒƒ์ด ์ข‹๊ฒ ์Šต๋‹ˆ๋‹ค. ๋˜ํ•œ, OpenAI API ํ˜ธ์ถœ ํšŸ์ˆ˜ ์ œํ•œ์— ๋Œ€ํ•œ ๋Œ€๋น„์ฑ…๋„ ๋งˆ๋ จํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

์ด๋ฒˆ PR์€ ์ƒˆ๋กœ์šด ๊ธฐ๋Šฅ ์ถ”๊ฐ€์™€ ๋ฐฐํฌ๋ฅผ ์œ„ํ•œ ์ค€๋น„ ์ž‘์—…์„ ํฌํ•จํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. ์ „๋ฐ˜์ ์œผ๋กœ ๋งŽ์€ ๋ถ€๋ถ„์ด ๊ฐœ์„ ๋˜์—ˆ์ง€๋งŒ, ๋ช‡ ๊ฐ€์ง€ ์ค‘์š”ํ•œ ์ˆ˜์ •์ด ํ•„์š”ํ•ด ๋ณด์ž…๋‹ˆ๋‹ค. ํŠนํžˆ Redis Stream์— ์ž‘์—…์„ ๋ฐœํ–‰ํ•˜๋Š” ๋กœ์ง์—์„œ ์ž‘์—… type์ด ์ž˜๋ชป ์ง€์ •๋˜์–ด ๋ฉ”์‹œ์ง€๊ฐ€ ์˜ฌ๋ฐ”๋ฅด๊ฒŒ ์ฒ˜๋ฆฌ๋˜์ง€ ์•Š๋Š” ์น˜๋ช…์ ์ธ ๋ฒ„๊ทธ๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค. ๋˜ํ•œ, ๋ฐฐํฌ ์Šคํฌ๋ฆฝํŠธ์˜ ๋ณ€์ˆ˜๋ช… ์˜คํƒ€๋กœ ์ธํ•ด ๋ฐฐํฌ๊ฐ€ ์‹คํŒจํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๋น„๋™๊ธฐ ์ฝ”๋“œ์—์„œ ๋™๊ธฐ ํ•จ์ˆ˜๋ฅผ ๋ถ€์ ์ ˆํ•˜๊ฒŒ ํ˜ธ์ถœํ•˜์—ฌ ์„ฑ๋Šฅ์„ ์ €ํ•˜์‹œํ‚ฌ ์ˆ˜ ์žˆ๋Š” ๋ถ€๋ถ„๊ณผ Pydantic ๋ชจ๋ธ์˜ ํ•„๋“œ๋ช… ๊ทœ์น™์ด ํŒŒ์ด์ฌ ํ‘œ์ค€(PEP 8)์„ ๋”ฐ๋ฅด์ง€ ์•Š๋Š” ์ ๋„ ์ˆ˜์ •์ด ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค. ์ž์„ธํ•œ ๋‚ด์šฉ์€ ๊ฐ ํŒŒ์ผ์— ๋‚จ๊ธด ์ฝ”๋ฉ˜ํŠธ๋ฅผ ์ฐธ๊ณ ํ•ด ์ฃผ์„ธ์š”.

replyQueue=settings.STREAM_RESULT,
callbackUrl=None,
contentType="image/jpeg",
contentType=job_request.contentType,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

job_request ๊ฐ์ฒด (ํƒ€์ž…: JobRequest)์—๋Š” contentType ์†์„ฑ์ด ์—†์Šต๋‹ˆ๋‹ค. JobRequest ๋ชจ๋ธ ์ •์˜์— contentType ํ•„๋“œ๊ฐ€ ๋ˆ„๋ฝ๋œ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค. ์ด ์ฝ”๋“œ๋Š” ์‹คํ–‰ ์‹œ AttributeError๋ฅผ ๋ฐœ์ƒ์‹œํ‚ต๋‹ˆ๋‹ค. JobRequest ์Šคํ‚ค๋งˆ์— contentType์„ ์ถ”๊ฐ€ํ•˜๊ณ  ์š”์ฒญ ๋ณธ๋ฌธ์— ํ•ด๋‹น ํ•„๋“œ๋ฅผ ํฌํ•จํ•˜๋„๋ก ์ˆ˜์ •ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

Comment on lines +35 to +39
{
"type": "image_results",
"payload": payload,
"correlationId": correlationId,
},

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

Redis Stream์— ๋ฐœํ–‰ํ•˜๋Š” ์ž‘์—…์˜ type์ด ์ž˜๋ชป ์„ค์ •๋˜์—ˆ์Šต๋‹ˆ๋‹ค. ํ˜„์žฌ "image_results"๋กœ ์„ค์ •๋˜์–ด ์žˆ์œผ๋‚˜, ์›Œ์ปค(app/worker/worker.py)๋Š” "image_jobs" ํƒ€์ž…์˜ ์ž‘์—…์„ ๊ธฐ๋Œ€ํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. ์ด ๋ถˆ์ผ์น˜๋กœ ์ธํ•ด ์ž‘์—…์ด ์ฒ˜๋ฆฌ๋˜์ง€ ์•Š๊ณ  Dead Letter Queue (DLQ)๋กœ ๋ณด๋‚ด์ง€๊ฒŒ ๋ฉ๋‹ˆ๋‹ค. ์ž‘์—… ํƒ€์ž…์„ "image_jobs"๋กœ ์ˆ˜์ •ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

        {
            "type": "image_jobs",
            "payload": payload,
            "correlationId": correlationId,
        }

Comment on lines +18 to +21
redis_client.xgroup_create(
stream_name=settings.STREAM_JOB,
group_name=settings.GROUP_NAME,
)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

redis_client.xgroup_create๋Š” ์ฝ”๋ฃจํ‹ด(coroutine)์ด๋ฏ€๋กœ await ํ‚ค์›Œ๋“œ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ํ˜ธ์ถœํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. await๊ฐ€ ์—†์œผ๋ฉด ๊ทธ๋ฃน์ด ์‹ค์ œ๋กœ ์ƒ์„ฑ๋˜์ง€ ์•Š์•„ ์›Œ์ปค๊ฐ€ ์ŠคํŠธ๋ฆผ ๋ฉ”์‹œ์ง€๋ฅผ ์ฝ์ง€ ๋ชปํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

Suggested change
redis_client.xgroup_create(
stream_name=settings.STREAM_JOB,
group_name=settings.GROUP_NAME,
)
await redis_client.xgroup_create(
stream_name=settings.STREAM_JOB,
group_name=settings.GROUP_NAME,
)

Comment on lines 31 to 32
if docker ps --filter "name=^/app-${AFTER_COLOR}$" --filter "status=running" --format '{{.Names}}' | grep -q .; then
echo "New app-${AFTER_COLOR} container is running."

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

์Šคํฌ๋ฆฝํŠธ์—์„œ AFTER_COLOR๋ผ๋Š” ๋ณ€์ˆ˜๋ฅผ ์‚ฌ์šฉํ•˜๊ณ  ์žˆ์ง€๋งŒ, ์ด ๋ณ€์ˆ˜๋Š” ์ •์˜๋˜์ง€ ์•Š์•˜์Šต๋‹ˆ๋‹ค. 14๋ฒˆ์งธ ๋˜๋Š” 19๋ฒˆ์งธ ์ค„์—์„œ ์ •์˜๋œ AFTER_COMPOSE_COLOR๋ฅผ ์‚ฌ์šฉํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. ์ด ์˜คํƒ€๋กœ ์ธํ•ด ๋ฐฐํฌ ์Šคํฌ๋ฆฝํŠธ๊ฐ€ ์ƒˆ ์ปจํ…Œ์ด๋„ˆ์˜ ์‹คํ–‰ ์ƒํƒœ๋ฅผ ์ œ๋Œ€๋กœ ํ™•์ธํ•˜์ง€ ๋ชปํ•˜๊ณ  ์‹คํŒจํ•˜๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.

Suggested change
if docker ps --filter "name=^/app-${AFTER_COLOR}$" --filter "status=running" --format '{{.Names}}' | grep -q .; then
echo "New app-${AFTER_COLOR} container is running."
if docker ps --filter "name=^/app-${AFTER_COMPOSE_COLOR}$" --filter "status=running" --format '{{.Names}}' | grep -q .; then
echo "New app-${AFTER_COMPOSE_COLOR} container is running."

Comment on lines +30 to +31
correlationId = job.correlationId
payload = json.dumps(job.dict())

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

์ด ๋ถ€๋ถ„์—๋Š” ๋‘ ๊ฐ€์ง€ ๊ฐœ์„ ์ ์ด ์žˆ์Šต๋‹ˆ๋‹ค:

  1. 30๋ฒˆ์งธ ์ค„์˜ correlationId = job.correlationId ํ• ๋‹น์€ ๋ถˆํ•„์š”ํ•ฉ๋‹ˆ๋‹ค. correlationId ๋ณ€์ˆ˜๋Š” ์ด๋ฏธ ์ด์ „์— ์ •์˜๋˜์—ˆ์œผ๋ฏ€๋กœ ์ด ์ค„์€ ์ œ๊ฑฐํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
  2. 31๋ฒˆ์งธ ์ค„์—์„œ Pydantic ๋ชจ๋ธ์„ ์ง๋ ฌํ™”ํ•˜๊ธฐ ์œ„ํ•ด job.dict()๋ฅผ ์‚ฌ์šฉํ•˜๊ณ  ์žˆ๋Š”๋ฐ, ์ด๋Š” ์˜ค๋ž˜๋œ(deprecated) ๋ฉ”์†Œ๋“œ์ž…๋‹ˆ๋‹ค. job.model_dump_json(by_alias=True)์„ ์‚ฌ์šฉํ•˜์—ฌ ๋” ๋ช…ํ™•ํ•˜๊ณ  ์•ˆ์ „ํ•˜๊ฒŒ JSON ๋ฌธ์ž์—ด์„ ์ƒ์„ฑํ•˜๋Š” ๊ฒƒ์ด ์ข‹์Šต๋‹ˆ๋‹ค.
Suggested change
correlationId = job.correlationId
payload = json.dumps(job.dict())
payload = job.model_dump_json(by_alias=True)

Comment on lines 4 to +26
class JobRequest(BaseModel):
presigned_url: str = Field(..., description="๋‹ค์šด๋กœ๋“œํ•  ์ด๋ฏธ์ง€์˜ Presigned URL")
presignedUrl: str = Field(..., description="๋‹ค์šด๋กœ๋“œํ•  ์ด๋ฏธ์ง€์˜ Presigned URL")

"""
FastAPI๊ฐ€ image.results Stream์— ๋ฐœํ–‰ํ•˜๋Š” ๋ฉ”์‹œ์ง€
"""
class JobResult(BaseModel):
pill_name: str
correlation_id: str
label: str
confidence: float
finished_at: str
correlationId: str
pillName: str
isSafe: int
description: str
finishedAt: str

"""
Spring์œผ๋กœ๋ถ€ํ„ฐ ๋ฐ›๋Š” Job(image.jobs ๊ตฌ๋…)
"""
class ImageJob(BaseModel):
correlation_id: str = Field(alias="correlationId")
presigned_url: str = Field(alias="presignedUrl")
reply_queue: str = Field(alias="replyQueue")
callback_url: str | None = Field(alias="callbackUrl")
content_type: str = Field(alias="contentType")
created_at: str = Field(alias="createdAt")
ttl_sec: int = Field(alias="ttlSec")
correlationId: str = Field(alias="correlationId")
presignedUrl: str = Field(alias="presignedUrl")
replyQueue: str = Field(alias="replyQueue")
contentType: str = Field(alias="contentType")
createdAt: str = Field(alias="createdAt")
ttlSec: int = Field(alias="ttlSec")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Pydantic ๋ชจ๋ธ๋“ค์˜ ํ•„๋“œ๋ช…์ด camelCase๋กœ ์ž‘์„ฑ๋˜์—ˆ์Šต๋‹ˆ๋‹ค. Python์—์„œ๋Š” PEP 8 ์Šคํƒ€์ผ ๊ฐ€์ด๋“œ์— ๋”ฐ๋ผ snake_case๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์ด ํ‘œ์ค€์ž…๋‹ˆ๋‹ค. ์™ธ๋ถ€ ์‹œ์Šคํ…œ๊ณผ์˜ JSON ๋ฐ์ดํ„ฐ ๊ตํ™˜์„ ์œ„ํ•ด camelCase๊ฐ€ ํ•„์š”ํ•˜๋‹ค๋ฉด, Python ์ฝ”๋“œ ๋‚ด์—์„œ๋Š” snake_case๋ฅผ ์‚ฌ์šฉํ•˜๊ณ  Pydantic์˜ Field(alias=...)๋ฅผ ํ†ตํ•ด JSON ํ•„๋“œ๋ช…์„ ๋งคํ•‘ํ•˜๋Š” ๊ฒƒ์ด ๊ฐ€์žฅ ์ข‹์€ ๋ฐฉ๋ฒ•์ž…๋‹ˆ๋‹ค. ์ด๋ ‡๊ฒŒ ํ•˜๋ฉด Python ์ฝ”๋“œ์˜ ๊ฐ€๋…์„ฑ๊ณผ ์ผ๊ด€์„ฑ์„ ์œ ์ง€ํ•˜๋ฉด์„œ ์™ธ๋ถ€ API์™€์˜ ํ˜ธํ™˜์„ฑ์„ ๋ณด์žฅํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

class JobRequest(BaseModel):
    presigned_url: str = Field(..., alias="presignedUrl", description="๋‹ค์šด๋กœ๋“œํ•  ์ด๋ฏธ์ง€์˜ Presigned URL")

"""
FastAPI๊ฐ€ image.results Stream์— ๋ฐœํ–‰ํ•˜๋Š” ๋ฉ”์‹œ์ง€
"""
class JobResult(BaseModel):
    correlation_id: str = Field(alias="correlationId")
    pill_name: str = Field(alias="pillName")
    is_safe: int = Field(alias="isSafe")
    description: str
    finished_at: str = Field(alias="finishedAt")

"""
Spring์œผ๋กœ๋ถ€ํ„ฐ ๋ฐ›๋Š” Job(image.jobs ๊ตฌ๋…)
"""
class ImageJob(BaseModel):
    correlation_id: str = Field(alias="correlationId")
    presigned_url: str = Field(alias="presignedUrl")
    reply_queue: str = Field(alias="replyQueue")
    content_type: str = Field(alias="contentType")
    created_at: str = Field(alias="createdAt")
    ttl_sec: int = Field(alias="ttlSec")

stream_file
)
print(f"[task] Start Asking GPT for job_id={correlationId}")
description, isSafe = checker.ask_chatgpt_about_pregnancy_safety(pillName)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

checker.ask_chatgpt_about_pregnancy_safety๋Š” OpenAI API๋ฅผ ํ˜ธ์ถœํ•˜๋Š” ๋™๊ธฐ ํ•จ์ˆ˜์ด๋ฉฐ, ๋„คํŠธ์›Œํฌ I/O๋กœ ์ธํ•ด ์ด๋ฒคํŠธ ๋ฃจํ”„๋ฅผ ์ฐจ๋‹จ(block)ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. asyncio.to_thread๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ด ํ•จ์ˆ˜๋ฅผ ๋ณ„๋„์˜ ์Šค๋ ˆ๋“œ์—์„œ ์‹คํ–‰ํ•จ์œผ๋กœ์จ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์˜ ์‘๋‹ต์„ฑ์„ ์œ ์ง€ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

Suggested change
description, isSafe = checker.ask_chatgpt_about_pregnancy_safety(pillName)
description, isSafe = await asyncio.to_thread(checker.ask_chatgpt_about_pregnancy_safety, pillName)

"""
์ด๋ฏธ์ง€๋ฅผ ๋‹ค์šด -> ๋‹ค์šด ํ•œ ๊ฒƒ์— ๋Œ€ํ•˜์—ฌ ๋ชจ๋ธ ๋ถ„์„ ์š”์ฒญ
"""
async def process_image_scan(job: ImageJob, redis_client: redis.Redis):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

process_image_scan ํ•จ์ˆ˜์˜ redis_client ํŒŒ๋ผ๋ฏธํ„ฐ ํƒ€์ž… ํžŒํŠธ๊ฐ€ redis.Redis๋กœ ๋˜์–ด ์žˆ์ง€๋งŒ, ์‹ค์ œ๋กœ๋Š” RedisStreamClient ์ธ์Šคํ„ด์Šค๊ฐ€ ์ „๋‹ฌ๋ฉ๋‹ˆ๋‹ค. RedisStreamClient๋Š” redis.Redis์˜ ์„œ๋ธŒํด๋ž˜์Šค๊ฐ€ ์•„๋‹ˆ๋ฏ€๋กœ, ์ด๋Š” ํƒ€์ž… ๋ถˆ์ผ์น˜์ž…๋‹ˆ๋‹ค. ์ฝ”๋“œ์˜ ๋ช…ํ™•์„ฑ๊ณผ ์ •์  ๋ถ„์„ ๋„๊ตฌ์™€์˜ ํ˜ธํ™˜์„ฑ์„ ์œ„ํ•ด ํƒ€์ž… ํžŒํŠธ๋ฅผ RedisStreamClient๋กœ ์ˆ˜์ •ํ•˜๋Š” ๊ฒƒ์ด ์ข‹์Šต๋‹ˆ๋‹ค. ์ด๋ฅผ ์œ„ํ•ด ํŒŒ์ผ ์ƒ๋‹จ์— from app.worker.redis_client import RedisStreamClient ์ž„ํฌํŠธ๊ฐ€ ํ•„์š”ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

Suggested change
async def process_image_scan(job: ImageJob, redis_client: redis.Redis):
async def process_image_scan(job: ImageJob, redis_client: "RedisStreamClient"):

Comment on lines +8 to +41
"""
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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

์ด ํŒŒ์ผ์— ์ •์˜๋œ _to_scalr, _decode, _sanitize_fields_for_xadd ํ—ฌํผ ํ•จ์ˆ˜๋“ค์€ app/worker/redis_client.py์— ์žˆ๋Š” _to_scalar, _sanitize_fields_for_xadd์™€ ๊ธฐ๋Šฅ์ ์œผ๋กœ ์ค‘๋ณต๋ฉ๋‹ˆ๋‹ค. ์ฝ”๋“œ ์ค‘๋ณต์„ ํ”ผํ•˜๊ณ  ์œ ์ง€๋ณด์ˆ˜์„ฑ์„ ๋†’์ด๊ธฐ ์œ„ํ•ด, redis_client.py์˜ ์œ ํ‹ธ๋ฆฌํ‹ฐ ํ•จ์ˆ˜๋“ค์„ ์žฌ์‚ฌ์šฉํ•˜๊ฑฐ๋‚˜ ํ•œ ๊ณณ์œผ๋กœ ํ†ตํ•ฉํ•˜๋Š” ๊ฒƒ์„ ๊ณ ๋ คํ•ด ๋ณด์„ธ์š”.

@youyeon11 youyeon11 merged commit ea44be6 into main Sep 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant