From 6b781f452061457e38a9f6c275d7c86e9ce258bc Mon Sep 17 00:00:00 2001 From: csct3434 Date: Wed, 15 May 2024 11:44:55 +0900 Subject: [PATCH 1/2] =?UTF-8?q?feat:=20Amazon=20SNS=20Topic=20=EB=A9=94?= =?UTF-8?q?=EC=84=B8=EC=A7=80=20=EC=A0=84=EC=86=A1=20Aspect=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 메서드의 실행 결과를 Amazon SNS 토픽으로 전송하는 NotifyResultAspect 구현 --- .../seasoning/common/aspect/NotifyResult.java | 15 +++++++++++ .../common/aspect/NotifyResultAspect.java | 26 +++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 src/main/java/today/seasoning/seasoning/common/aspect/NotifyResult.java create mode 100644 src/main/java/today/seasoning/seasoning/common/aspect/NotifyResultAspect.java diff --git a/src/main/java/today/seasoning/seasoning/common/aspect/NotifyResult.java b/src/main/java/today/seasoning/seasoning/common/aspect/NotifyResult.java new file mode 100644 index 0000000..b237317 --- /dev/null +++ b/src/main/java/today/seasoning/seasoning/common/aspect/NotifyResult.java @@ -0,0 +1,15 @@ +package today.seasoning.seasoning.common.aspect; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +// Amazon SNS Topic으로 실행 결과를 전송할 메서드에 붙이는 어노테이션 +@Target(ElementType.METHOD) +@Retention(RetentionPolicy.RUNTIME) +public @interface NotifyResult { + + // 작업명 + String name(); +} diff --git a/src/main/java/today/seasoning/seasoning/common/aspect/NotifyResultAspect.java b/src/main/java/today/seasoning/seasoning/common/aspect/NotifyResultAspect.java new file mode 100644 index 0000000..2e96fb1 --- /dev/null +++ b/src/main/java/today/seasoning/seasoning/common/aspect/NotifyResultAspect.java @@ -0,0 +1,26 @@ +package today.seasoning.seasoning.common.aspect; + +import lombok.RequiredArgsConstructor; +import org.aspectj.lang.annotation.AfterReturning; +import org.aspectj.lang.annotation.AfterThrowing; +import org.aspectj.lang.annotation.Aspect; +import org.springframework.stereotype.Component; +import today.seasoning.seasoning.common.aws.SnsService; + +@Aspect +@Component +@RequiredArgsConstructor +public class NotifyResultAspect { + + private final SnsService snsService; + + @AfterReturning(pointcut = "@annotation(notifyResult)") + public void reportSuccessResult(NotifyResult notifyResult) { + snsService.publish("[시즈닝] " + notifyResult.name() + " 완료"); + } + + @AfterThrowing(pointcut = "@annotation(notifyResult)") + public void reportFailureResult(NotifyResult notifyResult) { + snsService.publish("[시즈닝] " + notifyResult.name() + " 실패"); + } +} From d05146c5d125dc60d33ddbd01f1ea4cb239fabbf Mon Sep 17 00:00:00 2001 From: csct3434 Date: Wed, 15 May 2024 11:59:16 +0900 Subject: [PATCH 2/2] =?UTF-8?q?refactor:=20=EC=A0=88=EA=B8=B0=20=EB=93=B1?= =?UTF-8?q?=EB=A1=9D=20=EC=8A=A4=EC=BC=80=EC=A4=84=EB=A7=81=20=EC=9E=91?= =?UTF-8?q?=EC=97=85=EC=9C=BC=EB=A1=9C=EB=B6=80=ED=84=B0=20=EC=95=8C?= =?UTF-8?q?=EB=A6=BC=20=EC=A0=84=EC=86=A1=20=EA=B4=80=EC=8B=AC=EC=82=AC?= =?UTF-8?q?=EB=A5=BC=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit NotifyResultAspect를 적용하여 알림 전송 관심사를 절기 등록 스케줄링 작업으로부터 분리 --- .../RegisterNextYearSolarTermsService.java | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/src/main/java/today/seasoning/seasoning/solarterm/service/scheduled/RegisterNextYearSolarTermsService.java b/src/main/java/today/seasoning/seasoning/solarterm/service/scheduled/RegisterNextYearSolarTermsService.java index 3997d18..fe24e51 100644 --- a/src/main/java/today/seasoning/seasoning/solarterm/service/scheduled/RegisterNextYearSolarTermsService.java +++ b/src/main/java/today/seasoning/seasoning/solarterm/service/scheduled/RegisterNextYearSolarTermsService.java @@ -4,27 +4,20 @@ import lombok.RequiredArgsConstructor; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Service; -import today.seasoning.seasoning.common.aws.SnsService; +import today.seasoning.seasoning.common.aspect.NotifyResult; import today.seasoning.seasoning.solarterm.service.RegisterSolarTermsService; @Service @RequiredArgsConstructor public class RegisterNextYearSolarTermsService { - private final SnsService snsService; private final RegisterSolarTermsService registerSolarTermsService; @Scheduled(cron = "0 0 0 1 12 *") + @NotifyResult(name = "절기 등록 작업") public void doService() { int nextYear = LocalDate.now().getYear() + 1; - - try { - registerSolarTermsService.doService(nextYear); - - snsService.publish("[시즈닝] " + nextYear + "년 절기 등록 완료"); - } catch (Exception e) { - snsService.publish("[시즈닝] ERROR - " + nextYear + "년 절기 등록 실패"); - } + registerSolarTermsService.doService(nextYear); } }