From 9b2cac73e2e717700af1728601c163ce5b9391f0 Mon Sep 17 00:00:00 2001 From: mikekks Date: Wed, 17 Apr 2024 19:03:32 +0900 Subject: [PATCH 1/3] =?UTF-8?q?[FEAT]=20=EB=A9=94=EC=9D=BC=20=EB=B9=84?= =?UTF-8?q?=EB=8F=99=EA=B8=B0=20=EC=A0=84=EC=86=A1=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../RecruitmentApplicantRepository.java | 2 +- .../meeteam/global/config/AsyncConfig.java | 23 +++++++++++++++++++ .../synk/meeteam/infra/mail/MailService.java | 4 ++++ 3 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 src/main/java/synk/meeteam/global/config/AsyncConfig.java diff --git a/src/main/java/synk/meeteam/domain/recruitment/recruitment_applicant/repository/RecruitmentApplicantRepository.java b/src/main/java/synk/meeteam/domain/recruitment/recruitment_applicant/repository/RecruitmentApplicantRepository.java index f0ab8dcd..48de3717 100644 --- a/src/main/java/synk/meeteam/domain/recruitment/recruitment_applicant/repository/RecruitmentApplicantRepository.java +++ b/src/main/java/synk/meeteam/domain/recruitment/recruitment_applicant/repository/RecruitmentApplicantRepository.java @@ -16,7 +16,7 @@ public interface RecruitmentApplicantRepository extends JpaRepository, RecruitmentApplicantCustomRepository { - @Query("SELECT a FROM RecruitmentApplicant a JOIN FETCH a.recruitmentPost WHERE a.id IN :ids AND a.deleteStatus = synk.meeteam.global.entity.DeleteStatus.ALIVE") + @Query("SELECT a FROM RecruitmentApplicant a JOIN FETCH a.recruitmentPost JOIN FETCH a.applicant WHERE a.id IN :ids AND a.deleteStatus = synk.meeteam.global.entity.DeleteStatus.ALIVE") List findAllInApplicantId(@Param("ids") List applicantIds); Optional findByRecruitmentPostAndApplicantAndDeleteStatus(RecruitmentPost recruitmentPost, diff --git a/src/main/java/synk/meeteam/global/config/AsyncConfig.java b/src/main/java/synk/meeteam/global/config/AsyncConfig.java new file mode 100644 index 00000000..9cb11b02 --- /dev/null +++ b/src/main/java/synk/meeteam/global/config/AsyncConfig.java @@ -0,0 +1,23 @@ +package synk.meeteam.global.config; + +import java.util.concurrent.Executor; +import org.springframework.context.annotation.Configuration; +import org.springframework.scheduling.annotation.AsyncConfigurerSupport; +import org.springframework.scheduling.annotation.EnableAsync; +import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; + +@Configuration +@EnableAsync +public class AsyncConfig extends AsyncConfigurerSupport { + + public Executor getAsyncExecutor() { + ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); + executor.setCorePoolSize(2); // 기본적으로 실행 대기 중인 Thread 개수 + executor.setMaxPoolSize(10); // 동시에 동작하는 최대 Thread 개수 + executor.setQueueCapacity(500); // CorePool이 초과될때 Queue에 저장했다가 꺼내서 실행된다. (500개까지 저장함) + + executor.setThreadNamePrefix("async-"); // Spring에서 생성하는 Thread 이름의 접두사 + executor.initialize(); + return executor; + } +} diff --git a/src/main/java/synk/meeteam/infra/mail/MailService.java b/src/main/java/synk/meeteam/infra/mail/MailService.java index 19caaf7b..a47b8374 100644 --- a/src/main/java/synk/meeteam/infra/mail/MailService.java +++ b/src/main/java/synk/meeteam/infra/mail/MailService.java @@ -20,6 +20,7 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.mail.javamail.JavaMailSender; +import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.thymeleaf.TemplateEngine; @@ -74,6 +75,7 @@ public String generateEmailVerifyMailForm(String userName, String emailCode) { return templateEngine.process(MAIL_VERIFY_TEMPLATE, context); } + @Async @Transactional public void sendVerifyMail(String platformId, String receiverMail) { String newEmailCode = UUID.randomUUID().toString(); @@ -100,6 +102,8 @@ public void sendVerifyMail(String platformId, String receiverMail) { } } + + @Async @Transactional public void sendApproveMails(Long postId, List applicants, String writerName) { if (applicants == null) { From 74b3fd82290f4cf45278e590fb66a4a2068bf948 Mon Sep 17 00:00:00 2001 From: mikekks Date: Wed, 17 Apr 2024 19:09:36 +0900 Subject: [PATCH 2/3] =?UTF-8?q?[REFACTOR]=20=EC=8A=B9=EC=9D=B8=20=EC=88=98?= =?UTF-8?q?=20=EB=A7=8C=ED=81=BC=20=EC=8A=A4=EB=A0=88=EB=93=9C=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1=ED=95=98=EB=8F=84=EB=A1=9D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../facade/RecruitmentApplicantFacade.java | 5 +- .../synk/meeteam/infra/mail/MailService.java | 49 +++++++++---------- 2 files changed, 27 insertions(+), 27 deletions(-) diff --git a/src/main/java/synk/meeteam/domain/recruitment/recruitment_applicant/facade/RecruitmentApplicantFacade.java b/src/main/java/synk/meeteam/domain/recruitment/recruitment_applicant/facade/RecruitmentApplicantFacade.java index 7b891650..e230d9b4 100644 --- a/src/main/java/synk/meeteam/domain/recruitment/recruitment_applicant/facade/RecruitmentApplicantFacade.java +++ b/src/main/java/synk/meeteam/domain/recruitment/recruitment_applicant/facade/RecruitmentApplicantFacade.java @@ -39,7 +39,10 @@ public void approveApplicant(Long postId, Long userId, List applicantIds) RecruitmentPost recruitmentPost = recruitmentPostService.getRecruitmentPost(postId); User user = userService.findById(recruitmentPost.getCreatedBy()); - mailService.sendApproveMails(postId, applicants, user.getName()); + + applicants.stream().forEach( + applicant -> mailService.sendApproveMails(postId, applicant, user.getName()) + ); } @Transactional diff --git a/src/main/java/synk/meeteam/infra/mail/MailService.java b/src/main/java/synk/meeteam/infra/mail/MailService.java index a47b8374..f2e11976 100644 --- a/src/main/java/synk/meeteam/infra/mail/MailService.java +++ b/src/main/java/synk/meeteam/infra/mail/MailService.java @@ -105,34 +105,31 @@ public void sendVerifyMail(String platformId, String receiverMail) { @Async @Transactional - public void sendApproveMails(Long postId, List applicants, String writerName) { - if (applicants == null) { - return; - } + public void sendApproveMails(Long postId, RecruitmentApplicant recruitmentApplicant, String writerName) { + MimeMessage message = mailSender.createMimeMessage(); - for (RecruitmentApplicant recruitmentApplicant : applicants) { - User applicant = recruitmentApplicant.getApplicant(); - String receiverMail = - applicant.isUniversityMainEmail() ? applicant.getUniversityEmail() : applicant.getSubEmail(); - - try { - message.addRecipients(RecipientType.TO, receiverMail);// 받는 대상 - message.setSubject(MAIL_TITLE_APPROVE);// 제목 - - String body = generateApproveMailForm(applicant.getName(), postId.toString(), - recruitmentApplicant.getRecruitmentPost().getTitle(), - recruitmentApplicant.getRole().getName(), writerName, - recruitmentApplicant.getRecruitmentPost().getKakaoLink()); - - message.setText(body, CHAR_SET, SUB_TYPE);// 내용, charset 타입, subtype - // 보내는 사람의 이메일 주소, 보내는 사람 이름 - message.setFrom(new InternetAddress(SENDER_ADDRESS, SENDER));// 보내는 대상 - mailSender.send(message); // 메일 전송 - } catch (Exception e) { - log.info("{}", e); - throw new AuthException(INVALID_MAIL_SERVICE); - } + User applicant = recruitmentApplicant.getApplicant(); + + String receiverMail = + applicant.isUniversityMainEmail() ? applicant.getUniversityEmail() : applicant.getSubEmail(); + + try { + message.addRecipients(RecipientType.TO, receiverMail);// 받는 대상 + message.setSubject(MAIL_TITLE_APPROVE);// 제목 + + String body = generateApproveMailForm(applicant.getName(), postId.toString(), + recruitmentApplicant.getRecruitmentPost().getTitle(), + recruitmentApplicant.getRole().getName(), writerName, + recruitmentApplicant.getRecruitmentPost().getKakaoLink()); + + message.setText(body, CHAR_SET, SUB_TYPE);// 내용, charset 타입, subtype + // 보내는 사람의 이메일 주소, 보내는 사람 이름 + message.setFrom(new InternetAddress(SENDER_ADDRESS, SENDER));// 보내는 대상 + mailSender.send(message); // 메일 전송 + } catch (Exception e) { + log.info("{}", e); + throw new AuthException(INVALID_MAIL_SERVICE); } } From 9c09eef56615c10d1e5dd69f6f314af5bb584dfc Mon Sep 17 00:00:00 2001 From: mikekks Date: Wed, 17 Apr 2024 23:40:23 +0900 Subject: [PATCH 3/3] =?UTF-8?q?[CHORE]=20=EB=A9=94=EC=84=9C=EB=93=9C?= =?UTF-8?q?=EB=AA=85=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../facade/RecruitmentApplicantFacade.java | 2 +- src/main/java/synk/meeteam/infra/mail/MailService.java | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/java/synk/meeteam/domain/recruitment/recruitment_applicant/facade/RecruitmentApplicantFacade.java b/src/main/java/synk/meeteam/domain/recruitment/recruitment_applicant/facade/RecruitmentApplicantFacade.java index e230d9b4..ec1d67b9 100644 --- a/src/main/java/synk/meeteam/domain/recruitment/recruitment_applicant/facade/RecruitmentApplicantFacade.java +++ b/src/main/java/synk/meeteam/domain/recruitment/recruitment_applicant/facade/RecruitmentApplicantFacade.java @@ -41,7 +41,7 @@ public void approveApplicant(Long postId, Long userId, List applicantIds) User user = userService.findById(recruitmentPost.getCreatedBy()); applicants.stream().forEach( - applicant -> mailService.sendApproveMails(postId, applicant, user.getName()) + applicant -> mailService.sendApproveMail(postId, applicant, user.getName()) ); } diff --git a/src/main/java/synk/meeteam/infra/mail/MailService.java b/src/main/java/synk/meeteam/infra/mail/MailService.java index f2e11976..16b97612 100644 --- a/src/main/java/synk/meeteam/infra/mail/MailService.java +++ b/src/main/java/synk/meeteam/infra/mail/MailService.java @@ -15,7 +15,6 @@ import jakarta.mail.internet.InternetAddress; import jakarta.mail.internet.MimeMessage; import jakarta.mail.internet.MimeMessage.RecipientType; -import java.util.List; import java.util.UUID; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -105,7 +104,7 @@ public void sendVerifyMail(String platformId, String receiverMail) { @Async @Transactional - public void sendApproveMails(Long postId, RecruitmentApplicant recruitmentApplicant, String writerName) { + public void sendApproveMail(Long postId, RecruitmentApplicant recruitmentApplicant, String writerName) { MimeMessage message = mailSender.createMimeMessage();