Skip to content

Commit

Permalink
Merge pull request #71 from Genti2024/fix/gradle-test-fail-0724
Browse files Browse the repository at this point in the history
Ref: #70 Github Actions CI/CD 파이프라인에서 Test 제거
  • Loading branch information
LeeJae-H authored Jul 23, 2024
2 parents b5c54b4 + fa76a35 commit 11d986c
Show file tree
Hide file tree
Showing 10 changed files with 77 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/cicd-ec2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
@Data
public class GentiMatchResult {
RequestMatchStrategy requestMatchStrategy;
List<String> matchResult = new ArrayList<>();
List<String> 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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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()
));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -67,7 +66,7 @@ private void matchRequestsWithStrategy(List<PictureGenerateRequest> requestList,
}
}
}
logAndSendToDiscord(gentiMatchResult);
logAndPublishEvent(gentiMatchResult);
}

@Transactional
Expand Down Expand Up @@ -165,9 +164,9 @@ private List<Creator> 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);
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ class PictureGeneratePendingApiTest {
@Autowired
RequestMatchService requestMatchService;

@Transactional
@Test
@DisplayName("방금 생성하고 어드민에게 매칭된 사진생성요청은 유저입장에서 IN_PROGRESS로 보이는지 테스트")
void newlyCreatedAndMatchedToAdminPictureGenerateRequestIsInProgresstest() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.gt.genti.discord.event;

import java.util.List;

public record MatchEvent(String summary, List<String> matchResultList) {
public static MatchEvent of(String summary, List<String> matchResultList) {
return new MatchEvent(summary, matchResultList);
}
}

Original file line number Diff line number Diff line change
@@ -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()
);
}

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.gt.genti.discord;
package com.gt.genti.discord.event;

import java.time.LocalDateTime;

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 11d986c

Please sign in to comment.