From a5f7542e9b51748faf71af6353f97a661cb1a7cb Mon Sep 17 00:00:00 2001 From: BYEONGRYEOL Date: Wed, 24 Jul 2024 00:12:07 +0900 Subject: [PATCH 1/5] =?UTF-8?q?Fix:=20Test=20=EB=A9=94=EC=84=9C=EB=93=9C?= =?UTF-8?q?=EC=97=90=20@Transactional=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../test/java/com/gt/genti/PictureGeneratePendingApiTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/genti-api/src/test/java/com/gt/genti/PictureGeneratePendingApiTest.java b/genti-api/src/test/java/com/gt/genti/PictureGeneratePendingApiTest.java index 989f4bf0..f0d6502e 100644 --- a/genti-api/src/test/java/com/gt/genti/PictureGeneratePendingApiTest.java +++ b/genti-api/src/test/java/com/gt/genti/PictureGeneratePendingApiTest.java @@ -69,6 +69,7 @@ class PictureGeneratePendingApiTest { @Autowired RequestMatchService requestMatchService; + @Transactional @Test @DisplayName("방금 생성하고 어드민에게 매칭된 사진생성요청은 유저입장에서 IN_PROGRESS로 보이는지 테스트") void newlyCreatedAndMatchedToAdminPictureGenerateRequestIsInProgresstest() { From f4b276b1bd4f988acec37ecf4a1d0228ec1c182f Mon Sep 17 00:00:00 2001 From: BYEONGRYEOL Date: Wed, 24 Jul 2024 00:12:27 +0900 Subject: [PATCH 2/5] =?UTF-8?q?Rename:=20discord.event=20=ED=8C=A8?= =?UTF-8?q?=ED=82=A4=EC=A7=80=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/gt/genti/user/service/UserSignUpEventPublisher.java | 2 +- .../java/com/gt/genti/discord/{ => event}/SignUpEvent.java | 2 +- .../com/gt/genti/discord/{ => event}/SignUpEventListener.java | 4 +++- 3 files changed, 5 insertions(+), 3 deletions(-) rename genti-external/src/main/java/com/gt/genti/discord/{ => event}/SignUpEvent.java (91%) rename genti-external/src/main/java/com/gt/genti/discord/{ => event}/SignUpEventListener.java (87%) diff --git a/genti-api/src/main/java/com/gt/genti/user/service/UserSignUpEventPublisher.java b/genti-api/src/main/java/com/gt/genti/user/service/UserSignUpEventPublisher.java index e3a42b87..6999425e 100644 --- a/genti-api/src/main/java/com/gt/genti/user/service/UserSignUpEventPublisher.java +++ b/genti-api/src/main/java/com/gt/genti/user/service/UserSignUpEventPublisher.java @@ -6,7 +6,7 @@ import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; -import com.gt.genti.discord.SignUpEvent; +import com.gt.genti.discord.event.SignUpEvent; import com.gt.genti.user.model.User; import lombok.RequiredArgsConstructor; diff --git a/genti-external/src/main/java/com/gt/genti/discord/SignUpEvent.java b/genti-external/src/main/java/com/gt/genti/discord/event/SignUpEvent.java similarity index 91% rename from genti-external/src/main/java/com/gt/genti/discord/SignUpEvent.java rename to genti-external/src/main/java/com/gt/genti/discord/event/SignUpEvent.java index ae5444fb..b110e607 100644 --- a/genti-external/src/main/java/com/gt/genti/discord/SignUpEvent.java +++ b/genti-external/src/main/java/com/gt/genti/discord/event/SignUpEvent.java @@ -1,4 +1,4 @@ -package com.gt.genti.discord; +package com.gt.genti.discord.event; import java.time.LocalDateTime; diff --git a/genti-external/src/main/java/com/gt/genti/discord/SignUpEventListener.java b/genti-external/src/main/java/com/gt/genti/discord/event/SignUpEventListener.java similarity index 87% rename from genti-external/src/main/java/com/gt/genti/discord/SignUpEventListener.java rename to genti-external/src/main/java/com/gt/genti/discord/event/SignUpEventListener.java index 4d54cfa8..346b604b 100644 --- a/genti-external/src/main/java/com/gt/genti/discord/SignUpEventListener.java +++ b/genti-external/src/main/java/com/gt/genti/discord/event/SignUpEventListener.java @@ -1,9 +1,11 @@ -package com.gt.genti.discord; +package com.gt.genti.discord.event; import org.springframework.context.annotation.Profile; import org.springframework.context.event.EventListener; import org.springframework.stereotype.Component; +import com.gt.genti.discord.DiscordAppender; + import lombok.RequiredArgsConstructor; @Component From 8ea583a554b211cbf1b738914276598e37b307c6 Mon Sep 17 00:00:00 2001 From: BYEONGRYEOL Date: Wed, 24 Jul 2024 00:12:45 +0900 Subject: [PATCH 3/5] =?UTF-8?q?Rename:=20List=20=EB=B3=80=EC=88=98=20renam?= =?UTF-8?q?e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../picturegeneraterequest/service/GentiMatchResult.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/genti-api/src/main/java/com/gt/genti/picturegeneraterequest/service/GentiMatchResult.java b/genti-api/src/main/java/com/gt/genti/picturegeneraterequest/service/GentiMatchResult.java index c1e0cf90..61ef96d7 100644 --- a/genti-api/src/main/java/com/gt/genti/picturegeneraterequest/service/GentiMatchResult.java +++ b/genti-api/src/main/java/com/gt/genti/picturegeneraterequest/service/GentiMatchResult.java @@ -10,14 +10,14 @@ @Data public class GentiMatchResult { RequestMatchStrategy requestMatchStrategy; - List matchResult = new ArrayList<>(); + List matchResultList = new ArrayList<>(); String summary = ""; public GentiMatchResult(RequestMatchStrategy requestMatchStrategy) { this.requestMatchStrategy = requestMatchStrategy; } public void addMatchResult(String matchResult) { - this.matchResult.add(matchResult); + this.matchResultList.add(matchResult); } public void addSummary(String summary) { From 7be0110af6b461deab311637bb368fd8deeb83ec Mon Sep 17 00:00:00 2001 From: BYEONGRYEOL Date: Wed, 24 Jul 2024 00:13:18 +0900 Subject: [PATCH 4/5] =?UTF-8?q?Fix:=20event=20pub-sub=20=EA=B5=AC=EC=A1=B0?= =?UTF-8?q?=EB=A1=9C=20test=20=ED=99=98=EA=B2=BD=EC=97=90=EC=84=9C?= =?UTF-8?q?=EB=8A=94=20Discord=20=EC=95=8C=EB=A6=BC=20=EC=A0=84=EC=86=A1?= =?UTF-8?q?=20=EB=B0=A9=EC=A7=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/MatchEventPublisher.java | 28 +++++++++++++++++++ .../service/RequestMatchService.java | 9 +++--- .../gt/genti/discord/event/MatchEvent.java | 10 +++++++ .../discord/event/MatchEventListener.java | 26 +++++++++++++++++ 4 files changed, 68 insertions(+), 5 deletions(-) create mode 100644 genti-api/src/main/java/com/gt/genti/picturegeneraterequest/service/MatchEventPublisher.java create mode 100644 genti-external/src/main/java/com/gt/genti/discord/event/MatchEvent.java create mode 100644 genti-external/src/main/java/com/gt/genti/discord/event/MatchEventListener.java diff --git a/genti-api/src/main/java/com/gt/genti/picturegeneraterequest/service/MatchEventPublisher.java b/genti-api/src/main/java/com/gt/genti/picturegeneraterequest/service/MatchEventPublisher.java new file mode 100644 index 00000000..cadbcc8e --- /dev/null +++ b/genti-api/src/main/java/com/gt/genti/picturegeneraterequest/service/MatchEventPublisher.java @@ -0,0 +1,28 @@ +package com.gt.genti.picturegeneraterequest.service; + +import org.springframework.context.ApplicationEventPublisher; +import org.springframework.scheduling.annotation.Async; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Propagation; +import org.springframework.transaction.annotation.Transactional; + +import com.gt.genti.discord.event.MatchEvent; + +import lombok.RequiredArgsConstructor; + +@Service +@RequiredArgsConstructor +public class MatchEventPublisher { + + private final ApplicationEventPublisher eventPublisher; + + @Async + @Transactional(propagation = Propagation.REQUIRES_NEW) + public void publishSignUpEvent(GentiMatchResult gentiMatchResult) { + eventPublisher.publishEvent(MatchEvent.of( + gentiMatchResult.getSummary(), + gentiMatchResult.getMatchResultList() + )); + } + +} diff --git a/genti-api/src/main/java/com/gt/genti/picturegeneraterequest/service/RequestMatchService.java b/genti-api/src/main/java/com/gt/genti/picturegeneraterequest/service/RequestMatchService.java index a2d96f64..d5ecfaad 100644 --- a/genti-api/src/main/java/com/gt/genti/picturegeneraterequest/service/RequestMatchService.java +++ b/genti-api/src/main/java/com/gt/genti/picturegeneraterequest/service/RequestMatchService.java @@ -11,7 +11,6 @@ import com.gt.genti.common.AdminService; import com.gt.genti.creator.model.Creator; import com.gt.genti.creator.repository.CreatorRepository; -import com.gt.genti.discord.DiscordAppender; import com.gt.genti.matchingstrategy.model.RequestMatchStrategy; import com.gt.genti.picturegeneraterequest.model.PictureGenerateRequest; import com.gt.genti.picturegeneraterequest.repository.PictureGenerateRequestRepository; @@ -30,7 +29,7 @@ public class RequestMatchService { private final PictureGenerateRequestRepository pictureGenerateRequestRepository; private final PictureGenerateResponseRepository pictureGenerateResponseRepository; private final AdminService adminService; - private final DiscordAppender discordAppender; + private final MatchEventPublisher matchEventPublisher; @Getter private RequestMatchStrategy currentStrategy = RequestMatchStrategy.ADMIN_ONLY; @@ -67,7 +66,7 @@ private void matchRequestsWithStrategy(List requestList, } } } - logAndSendToDiscord(gentiMatchResult); + logAndPublishEvent(gentiMatchResult); } @Transactional @@ -165,9 +164,9 @@ private List getAvailableCreators() { .collect(Collectors.toList()); } - private void logAndSendToDiscord(GentiMatchResult gentiMatchResult) { + private void logAndPublishEvent(GentiMatchResult gentiMatchResult) { log.info(gentiMatchResult.toString()); - discordAppender.matchResultAppend(gentiMatchResult.getSummary(), gentiMatchResult.getMatchResult()); + matchEventPublisher.publishSignUpEvent(gentiMatchResult); } } diff --git a/genti-external/src/main/java/com/gt/genti/discord/event/MatchEvent.java b/genti-external/src/main/java/com/gt/genti/discord/event/MatchEvent.java new file mode 100644 index 00000000..20d99468 --- /dev/null +++ b/genti-external/src/main/java/com/gt/genti/discord/event/MatchEvent.java @@ -0,0 +1,10 @@ +package com.gt.genti.discord.event; + +import java.util.List; + +public record MatchEvent(String summary, List matchResultList) { + public static MatchEvent of(String summary, List matchResultList) { + return new MatchEvent(summary, matchResultList); + } +} + diff --git a/genti-external/src/main/java/com/gt/genti/discord/event/MatchEventListener.java b/genti-external/src/main/java/com/gt/genti/discord/event/MatchEventListener.java new file mode 100644 index 00000000..ddf6ac5c --- /dev/null +++ b/genti-external/src/main/java/com/gt/genti/discord/event/MatchEventListener.java @@ -0,0 +1,26 @@ +package com.gt.genti.discord.event; + +import org.springframework.context.annotation.Profile; +import org.springframework.context.event.EventListener; +import org.springframework.stereotype.Component; + +import com.gt.genti.discord.DiscordAppender; + +import lombok.RequiredArgsConstructor; + +@Component +@Profile({"local", "deploy"}) +@RequiredArgsConstructor +public class MatchEventListener { + + private final DiscordAppender discordAppender; + + @EventListener + public void handleMatchEvent(MatchEvent event) { + discordAppender.matchResultAppend( + event.summary(), + event.matchResultList() + ); + } + +} From fa76a3519cc866fd5516516f6d1452c820a328f9 Mon Sep 17 00:00:00 2001 From: BYEONGRYEOL Date: Wed, 24 Jul 2024 00:13:41 +0900 Subject: [PATCH 5/5] =?UTF-8?q?Fix:=20ci/cd=20=ED=8C=8C=EC=9D=B4=ED=94=84?= =?UTF-8?q?=EB=9D=BC=EC=9D=B8=20=EB=B9=8C=EB=93=9C=20=EC=A4=91=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=ED=95=98=EC=A7=80=EC=95=8A=EC=9D=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/cicd-ec2.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cicd-ec2.yml b/.github/workflows/cicd-ec2.yml index 31305381..45a092dc 100644 --- a/.github/workflows/cicd-ec2.yml +++ b/.github/workflows/cicd-ec2.yml @@ -59,7 +59,7 @@ jobs: - name: Build with Gradle Wrapper run: | chmod +x ./gradlew - ./gradlew clean build + ./gradlew clean build -x test - name: Get Github action IP