-
Notifications
You must be signed in to change notification settings - Fork 0
10차 배포 -3 #357
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
10차 배포 -3 #357
Changes from all commits
b1ba939
459e4fd
336c5c8
a1d8cc9
2131310
2827734
d2ae5bc
c91c506
67c5cec
39ab7c9
4f65009
90ea1e2
4cf1788
81982f7
c771394
665ad90
e01af5d
2020cd7
522f2a6
b62e9dc
8f709c9
ffb0b26
37442c4
59722ea
29e534b
1153d5a
136b1d2
f3fcb89
2c519b6
89994a4
4143640
a6ec161
abff1c1
44233d9
2e014b1
238e510
35e179f
2e2a380
49cc5c4
61dd151
a93a633
0887df1
52d8747
6057919
dace8a9
1fc84be
fde63d0
dc1a06b
0a078b3
00747af
be882e3
3baf85d
76b031b
93a9f29
ab69da1
37d6728
02f799e
12e5f37
95390f7
5ce05fe
0713c4d
95bc72b
5c69146
03180f2
1361f2e
90e89ad
5d84aa2
9b45723
814faf9
12b29ae
26760b1
1d13f88
9226662
9b1e26a
3f71f42
7a0161a
12eac38
df9e3f9
27acc2d
df096d9
1ff09fa
9948ef0
f71d79d
97840af
c426db7
b9e638f
59388ed
c3e1cd4
272e29c
1523163
2d7d7d4
11547ad
985c025
a109ff4
b694483
9c7427b
8be4bf2
65e6af1
370e5f1
6975d59
26fffd4
ab48c1d
253e6bf
96fe597
1a3ee89
6632ecf
161d4db
71d3edc
9d71ba3
44a10a4
b379ebf
e1839ca
bd2d44f
1080b5d
d94217e
376cf7c
4ac4f51
eb90071
d4c20ce
c8e2a47
457e712
da7113f
e894ec0
b48506c
df52746
0c91a25
dcecfd9
fe64452
f820108
1a8a0f9
393f319
894c648
b54958b
2ed4bff
72ad88b
2b62ee2
ea10a74
a75096d
f5588b6
ca850f0
efd49b6
37bfd4d
8ac45e9
2af0c96
06378eb
7278f64
6a3bb0b
11a1f6a
9df5c05
30cf3d2
1825286
45da619
19e63d5
a7aeb97
d4f2bc9
3dff705
a2dfc3b
75cc207
7ab5655
b8be542
caee534
1757410
bf6c944
0d50d46
2963912
0e5105d
cbdd9a3
8010f71
ce1eabb
775e584
7fadb7e
adc4e1f
ac3374f
86fbc96
1a7fb83
22756be
dda8f2f
36b7e7a
5c609c0
71538e0
3777783
d2c85b6
db7b7ae
89fd291
7d6a04b
9da93b8
6e39426
aa29e60
38c6075
261414c
b43fff0
1e9228b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,16 +2,33 @@ | |
|
|
||
| import com.example.cs25batch.batch.dto.MailDto; | ||
| import com.example.cs25batch.batch.service.JavaMailService; | ||
| import io.github.bucket4j.Bandwidth; | ||
| import io.github.bucket4j.Bucket; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.stereotype.Component; | ||
|
|
||
| import java.time.Duration; | ||
|
|
||
|
Comment on lines
+5
to
+11
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent 🧩 Analysis chainBucket4j API 버전 확인
🏁 Script executed: #!/bin/bash
# 저장소 내 Bucket4j 의존성 및 버전 확인
fd -HIa 'build.gradle*' 'pom.xml' | xargs -I{} sh -c 'echo ">>> {}"; sed -n "1,200p" "{}" | rg -n "bucket4j|io.github.bucket4j" -A 2'Length of output: 230 🏁 Script executed: #!/bin/bash
# 저장소 루트에서 pom.xml, build.gradle, build.gradle.kts 파일을 찾아 Bucket4j 의존성 및 버전 확인
find . -maxdepth 2 -type f \( -name 'pom.xml' -o -name 'build.gradle' -o -name 'build.gradle.kts' \) | while read file; do
echo ">>> $file"
sed -n '1,200p' "$file" | rg -n "io\.github\.bucket4j" -A 2 || echo " → Bucket4j 의존성이 없습니다."
doneLength of output: 1169 Bucket4j 의존성 선언 및 버전 확인 필요
– 수정 위치 – 예시 추가 코드 dependencies {
// 필요한 버전으로 조정하세요
implementation 'com.github.bucket4j:bucket4j-core:7.6.0'
}🤖 Prompt for AI Agents |
||
| @Component("javaBatchMailSender") | ||
| @RequiredArgsConstructor | ||
| public class JavaMailSenderStrategy implements MailSenderStrategy{ | ||
| private final JavaMailService javaMailService; | ||
| private final Bucket bucket = Bucket.builder() | ||
| .addLimit( | ||
| Bandwidth.builder() | ||
| .capacity(4) | ||
| .refillGreedy(2, Duration.ofMillis(500)) | ||
| .build() | ||
| ) | ||
| .build(); | ||
|
Comment on lines
+16
to
+23
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion 레이트 리밋 상수 하드코딩 → 설정 외부화 권장 capacity(4), refill(2/500ms)을 코드에 고정하지 말고 프로퍼티로 외부화하면 환경별/전략별로 유연하게 조정할 수 있습니다. SES/자바메일 전략 간 할당량 차이도 설정만으로 관리 가능합니다. 권장: 🤖 Prompt for AI Agents |
||
|
|
||
| @Override | ||
| public void sendQuizMail(MailDto mailDto) { | ||
| javaMailService.sendQuizEmail(mailDto.getSubscription(), mailDto.getQuiz()); // 커스텀 메서드로 정의 | ||
| } | ||
|
|
||
| @Override | ||
| public Bucket getBucket() { | ||
| return bucket; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,10 @@ | ||
| package com.example.cs25batch.sender; | ||
|
|
||
| import com.example.cs25batch.batch.dto.MailDto; | ||
| import io.github.bucket4j.Bucket; | ||
|
|
||
| public interface MailSenderStrategy { | ||
| void sendQuizMail(MailDto mailDto); | ||
|
|
||
| Bucket getBucket(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Bucket을 인터페이스로 직접 노출 → 추상화 누수 전략의 내부 구현(버킷)을 외부로 노출하면 결합도가 올라가고 사용처가 토큰 소비 정책을 분산해서 갖게 됩니다. 점진적 마이그레이션을 위해 기본 메서드로 토큰 소비 API를 제공한 뒤, 사용처에서는 이를 호출하도록 전환하는 방식을 권장합니다. 아래처럼 기본 메서드를 추가해 외부가 버킷 인지 없이 토큰 소비만 하도록 유도할 수 있습니다. public interface MailSenderStrategy {
void sendQuizMail(MailDto mailDto);
Bucket getBucket();
+
+ default boolean tryConsume(long tokens) {
+ return getBucket().tryConsume(tokens);
+ }
}🤖 Prompt for AI Agents |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,17 +2,34 @@ | |
|
|
||
| import com.example.cs25batch.batch.dto.MailDto; | ||
| import com.example.cs25batch.batch.service.SesMailService; | ||
| import io.github.bucket4j.Bandwidth; | ||
| import io.github.bucket4j.Bucket; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.stereotype.Component; | ||
|
|
||
| import java.time.Duration; | ||
|
|
||
| @RequiredArgsConstructor | ||
| @Component("sesMailSender") | ||
| public class SesMailSenderStrategy implements MailSenderStrategy{ | ||
|
|
||
| private final SesMailService sesMailService; | ||
| private final Bucket bucket = Bucket.builder() | ||
| .addLimit( | ||
| Bandwidth.builder() | ||
| .capacity(14) | ||
| .refillGreedy(7, Duration.ofMillis(500)) | ||
| .build() | ||
| ) | ||
| .build(); | ||
|
Comment on lines
+17
to
+24
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion 레이트 리밋 상수 하드코딩 → 설정 외부화 권장 capacity(14), refill(7/500ms) 값이 코드에 고정되어 있어 환경별(개발/스테이징/운영, 리전/SES 할당량) 조정이 어렵습니다. 예시(요약):
🤖 Prompt for AI Agents |
||
|
|
||
| @Override | ||
| public void sendQuizMail(MailDto mailDto) { | ||
| sesMailService.sendQuizEmail(mailDto.getSubscription(), mailDto.getQuiz()); | ||
| } | ||
|
|
||
| @Override | ||
| public Bucket getBucket() { | ||
| return bucket; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -3,6 +3,8 @@ | |||||||||||||||||||||||||
| import com.example.cs25batch.batch.dto.MailDto; | ||||||||||||||||||||||||||
| import com.example.cs25batch.sender.MailSenderStrategy; | ||||||||||||||||||||||||||
| import java.util.Map; | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| import io.github.bucket4j.Bucket; | ||||||||||||||||||||||||||
| import lombok.RequiredArgsConstructor; | ||||||||||||||||||||||||||
| import org.springframework.stereotype.Component; | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
|
|
@@ -12,10 +14,21 @@ public class MailSenderContext { | |||||||||||||||||||||||||
| private final Map<String, MailSenderStrategy> strategyMap; | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| public void send(MailDto dto, String strategyKey) { | ||||||||||||||||||||||||||
| MailSenderStrategy strategy = getValidStrategy(strategyKey); | ||||||||||||||||||||||||||
| strategy.sendQuizMail(dto); | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| public Bucket getBucket(String strategyKey) { | ||||||||||||||||||||||||||
| MailSenderStrategy strategy = getValidStrategy(strategyKey); | ||||||||||||||||||||||||||
| return strategy.getBucket(); | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
Comment on lines
+21
to
+24
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion 버킷 직접 반환 대신 소비 위임 메서드 추가 권장 컨텍스트에서 토큰 소비를 대행하면 호출처는 버킷을 알 필요가 없습니다. 아래처럼 public Bucket getBucket(String strategyKey) {
MailSenderStrategy strategy = getValidStrategy(strategyKey);
return strategy.getBucket();
}
+
+ public boolean tryConsume(String strategyKey, long tokens) {
+ return getValidStrategy(strategyKey).getBucket().tryConsume(tokens);
+ }📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| private MailSenderStrategy getValidStrategy(String strategyKey) { | ||||||||||||||||||||||||||
| MailSenderStrategy strategy = strategyMap.get(strategyKey); | ||||||||||||||||||||||||||
| if (strategy == null) { | ||||||||||||||||||||||||||
| throw new IllegalArgumentException("메일 전략이 존재하지 않습니다: " + strategyKey); | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| strategy.sendQuizMail(dto); | ||||||||||||||||||||||||||
| return strategy; | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
버킷 직접 획득/루프 대신 컨텍스트 위임 사용
컨텍스트에
tryConsume(strategyKey, tokens)를 추가했다면 아래처럼 호출부를 단순화할 수 있습니다. 버킷 구현/정책을 호출처에서 몰라도 되며, 이후 정책 변경 시 영향 범위를 줄일 수 있습니다.참고: 이 변경 후
io.github.bucket4j.Bucketimport는 불필요해집니다(정리 권장).📝 Committable suggestion
🤖 Prompt for AI Agents