Skip to content

🔀 :: [#819] - 애플리케이션 비동기 작업에도 락이 적용되도록 수정 - #820

Merged
dolong2 merged 4 commits into
developfrom
refac/lock
Jul 11, 2026
Merged

🔀 :: [#819] - 애플리케이션 비동기 작업에도 락이 적용되도록 수정#820
dolong2 merged 4 commits into
developfrom
refac/lock

Conversation

@dolong2

@dolong2 dolong2 commented Jul 11, 2026

Copy link
Copy Markdown
Owner

개요

  • 애플리케이션에 관련된 비동기 작업에도 락이 적용되도록 수정합니다.

작업내용

  • 애플리케이션의 컨테이너 빌드 로직을 서비스로 분리
    • 해당 서비스의 메서드에 락 어노테이션 적용

체크리스트

탬플릿외에 필요한 항목이 있으면 추가해주세요.

  • 로컬에서 빌드가 성공하나요?
  • 추가(수정)한 코드가 정상적으로 동작하나요?
  • pr 타켓 브랜치가 맞게 설정되어 있나요?
  • pr에서 작업할 내용만 작업됐나요?
  • 기존 API와 호환되지 않는 사항이 있나요?

기타

  • 현재 구현된 LockAspect가 비동기를 커버하도록 수정할 수 없기때문에, 비동기로 실행되는 작업중 락이 필요한 부분을 서비스로 분리해서 해당 서비스에 Lock을 적용하는 방식으로 수정

Summary by CodeRabbit

  • 개선 사항
    • 애플리케이션 생성, 배포, 수정 후 갱신 과정을 하나의 공통 흐름으로 통합했습니다.
    • 갱신 시 소스 동기화, 이미지 생성 및 빌드, 볼륨 연결, 컨테이너 생성, 임시 디렉터리 정리가 일관되게 처리됩니다.
    • 동일 애플리케이션에 대한 중복 갱신을 제어해 배포 안정성을 높였습니다.
    • 배포 후속 작업이 간소화되어 애플리케이션 상태 전환과 갱신 처리가 더욱 일관되게 동작합니다.

@dolong2 dolong2 self-assigned this Jul 11, 2026
@dolong2 dolong2 added 1️⃣ Priority: 상 우선순위 상 🔨 Refactor 코드 리팩토링 labels Jul 11, 2026
@dolong2 dolong2 linked an issue Jul 11, 2026 that may be closed by this pull request
@coderabbitai

coderabbitai Bot commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

애플리케이션 생성·수정·배포 이벤트의 직접적인 클론, 이미지, 컨테이너, 볼륨 처리를 RefreshApplicationService로 통합했다. 새 구현체는 잠금 하에 리프레시 작업을 순차 수행하며, 각 유스케이스와 이벤트 리스너가 이를 호출한다.

Changes

애플리케이션 리프레시 흐름

Layer / File(s) Summary
리프레시 서비스 계약과 구현
src/main/kotlin/com/dcd/server/core/domain/application/service/RefreshApplicationService.kt, src/main/kotlin/com/dcd/server/core/domain/application/service/impl/RefreshApplicationServiceImpl.kt
suspend refresh(application) 계약과 잠금 기반의 저장소 클론, 이미지 파일 생성, 이미지 빌드, 볼륨 조회, 컨테이너 생성, 디렉터리 삭제 구현을 추가했다.
생성·수정·이벤트 처리 위임
src/main/kotlin/com/dcd/server/core/domain/application/usecase/CreateApplicationUseCase.kt, src/main/kotlin/com/dcd/server/core/domain/application/usecase/UpdateApplicationUseCase.kt, src/main/kotlin/com/dcd/server/core/domain/application/event/listener/ApplicationEventListener.kt
생성, 이름 변경, 배포 이벤트 처리에서 직접 수행하던 후속 프로비저닝을 refreshApplicationService.refresh(...) 호출로 변경했다.
배포 유스케이스 위임
src/main/kotlin/com/dcd/server/core/domain/application/usecase/DeployApplicationUseCase.kt
기존 컨테이너·이미지 정리 후 리프레시 서비스를 호출하도록 의존성과 배포 흐름을 변경했다.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant CreateOrDeployUseCase
  participant RefreshApplicationService
  participant ApplicationRemoteRepoPort
  participant ContainerPort
  participant DeleteApplicationDirectoryService
  CreateOrDeployUseCase->>RefreshApplicationService: refresh(application)
  RefreshApplicationService->>ApplicationRemoteRepoPort: cloneApplicationRemoteRepo(application)
  RefreshApplicationService->>ContainerPort: buildImage(application)
  RefreshApplicationService->>ContainerPort: createContainer(application, volumeMounts)
  RefreshApplicationService->>DeleteApplicationDirectoryService: deleteApplicationDirectory(application)
Loading

Possibly related PRs

  • dolong2/dcd#695: DeployApplicationEvent와 이벤트 리스너의 동일한 배포 처리 경로를 다룹니다.
  • dolong2/dcd#774: containerPort 추상화를 통한 클론·빌드·컨테이너 처리와 연결됩니다.
  • dolong2/dcd#788: 이미지 파일 생성 서비스 계약과 호출 계층을 함께 다룹니다.

Poem

깡충 토끼가 리프레시를 부르면
클론과 이미지가 줄을 서고,
컨테이너도 폴짝 올라타요.
볼륨은 착착, 디렉터리는 사라락—
새 서비스 하나로 배포가 춤춰요! 🐇

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed 비동기 애플리케이션 작업에 락을 적용하는 핵심 변경을 정확히 요약해 변경 내용과 잘 맞습니다.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch refac/lock

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
src/main/kotlin/com/dcd/server/core/domain/application/service/impl/RefreshApplicationServiceImpl.kt (1)

25-30: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

else -> {} 분기에 의도를 명시하는 코멘트를 추가하는 것을 권장합니다.

SPRING_BOOT, NEST_JS, GIN 타입만 원격 저장소 클론을 수행하고 다른 타입은 생략합니다. 이것이 의도적이라면, 어떤 타입이 클론이 불필요한지(예: 정적 사이트, DB 등) 간단한 코멘트로 명시하면 유지보수에 도움이 됩니다.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@src/main/kotlin/com/dcd/server/core/domain/application/service/impl/RefreshApplicationServiceImpl.kt`
around lines 25 - 30, In the when expression within
RefreshApplicationServiceImpl, add a concise comment to the else branch
explaining that cloning is intentionally skipped for application types that do
not require a remote repository, such as static sites or databases.
src/main/kotlin/com/dcd/server/core/domain/application/usecase/DeployApplicationUseCase.kt (1)

79-90: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick win

suspend fun 내부의 runBlocking은 IO 스레드를 블로킹합니다.

deployApplication은 이미 suspend이며 launch { ... }와 채널 소비 코루틴에서 호출됩니다. 여기서 runBlocking을 사용하면 해당 코루틴이 점유한 Dispatchers.IO 스레드를 완료까지 블로킹하여, 동시 처리(1..3 워커) 효과를 떨어뜨리고 스레드 풀 고갈 위험이 있습니다. suspend 컨텍스트를 그대로 사용하도록 runBlocking을 제거하는 것을 권장합니다.

♻️ 제안 변경
 private suspend fun deployApplication(application: Application) {
-    runBlocking {
-        containerPort.execute {
-            deleteContainer(application)
-            deleteImage(application)
-        }
-
-        refreshApplicationService.refresh(application)
-
-        eventPublisher.publishEvent(ChangeApplicationStatusEvent(ApplicationStatus.STOPPED, application))
-    }
+    containerPort.execute {
+        deleteContainer(application)
+        deleteImage(application)
+    }
+
+    refreshApplicationService.refresh(application)
+
+    eventPublisher.publishEvent(ChangeApplicationStatusEvent(ApplicationStatus.STOPPED, application))
 }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@src/main/kotlin/com/dcd/server/core/domain/application/usecase/DeployApplicationUseCase.kt`
around lines 79 - 90, deployApplication 내부의 runBlocking이 이미 suspend 함수인 실행 흐름을
불필요하게 블로킹합니다. deployApplication에서 runBlocking을 제거하고 containerPort.execute,
refreshApplicationService.refresh, eventPublisher.publishEvent를 현재 suspend
컨텍스트에서 순차 호출하도록 수정하세요.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@src/main/kotlin/com/dcd/server/core/domain/application/service/impl/RefreshApplicationServiceImpl.kt`:
- Around line 23-41: refresh 내부의 예외가 애플리케이션을 PENDING 상태로 남기고 호출자에서 처리되지 않는 문제를
수정하세요. RefreshApplicationServiceImpl의 refresh에서 저장소 복제, 이미지 생성, 컨테이너 생성 및 정리 작업을
try-catch로 감싸고, 실패 시 적절한 실패 상태 전환 이벤트를 발행하거나 상태를 복구한 뒤 예외를 다시 전달하세요. 또한
CreateApplicationUseCase, UpdateApplicationUseCase, ApplicationEventListener의
launch 블록이 실패를 관찰하고 처리할 수 있도록 예외 처리 흐름을 보완하세요.

---

Nitpick comments:
In
`@src/main/kotlin/com/dcd/server/core/domain/application/service/impl/RefreshApplicationServiceImpl.kt`:
- Around line 25-30: In the when expression within
RefreshApplicationServiceImpl, add a concise comment to the else branch
explaining that cloning is intentionally skipped for application types that do
not require a remote repository, such as static sites or databases.

In
`@src/main/kotlin/com/dcd/server/core/domain/application/usecase/DeployApplicationUseCase.kt`:
- Around line 79-90: deployApplication 내부의 runBlocking이 이미 suspend 함수인 실행 흐름을
불필요하게 블로킹합니다. deployApplication에서 runBlocking을 제거하고 containerPort.execute,
refreshApplicationService.refresh, eventPublisher.publishEvent를 현재 suspend
컨텍스트에서 순차 호출하도록 수정하세요.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 6a1c9477-5d92-47a4-8193-756f8b97dec3

📥 Commits

Reviewing files that changed from the base of the PR and between 2931a4c and a1ae48c.

📒 Files selected for processing (6)
  • src/main/kotlin/com/dcd/server/core/domain/application/event/listener/ApplicationEventListener.kt
  • src/main/kotlin/com/dcd/server/core/domain/application/service/RefreshApplicationService.kt
  • src/main/kotlin/com/dcd/server/core/domain/application/service/impl/RefreshApplicationServiceImpl.kt
  • src/main/kotlin/com/dcd/server/core/domain/application/usecase/CreateApplicationUseCase.kt
  • src/main/kotlin/com/dcd/server/core/domain/application/usecase/DeployApplicationUseCase.kt
  • src/main/kotlin/com/dcd/server/core/domain/application/usecase/UpdateApplicationUseCase.kt

@dolong2
dolong2 merged commit 0d835e9 into develop Jul 11, 2026
2 checks passed
@dolong2
dolong2 deleted the refac/lock branch July 11, 2026 06:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🔨 Refactor 코드 리팩토링 1️⃣ Priority: 상 우선순위 상

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Lock이 비동기도 보장할수있도록 리펙토링

1 participant