-
Notifications
You must be signed in to change notification settings - Fork 0
[FEAT] 알람 클라우드 태스크 구현 #73
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
Open
paragon0107
wants to merge
27
commits into
develop
Choose a base branch
from
feat/#61-schedule-alarm
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
6215ac5
chore: 임시 커밋
paragon0107 11b6b01
Merge branch 'feat/#61-schedule-alarm' of https://github.com/dev-meme…
paragon0107 db6f17d
chore: 스케줄 엔티티 스케줄링 관련 조회 메서드 네이밍 변경
paragon0107 4cb50bd
chore: 스케줄 엔티티 스케줄링 관련 조회 프로젝션 추가
paragon0107 a008577
chore: 스케줄 알람 시간 추가
paragon0107 f2a582c
feat: querydsl 추가
paragon0107 9b0e841
feat: querydsl 설정
paragon0107 6e8fa80
feat: ScheduleAlarmCustomRepository 부분 구현
paragon0107 be5f723
feat: ScheduleAlarmCustomRepository 부분 구현
paragon0107 2356c1d
feat: ScheduleAlarmRepository 구현
paragon0107 d34aa77
feat: ScheduleAlarmService 구현
paragon0107 b983425
feat: ScheduleAlarmService 분리
paragon0107 b002e86
feat: ScheduleAlarm 분리
paragon0107 633250e
feat: ScheduleAlarm 도메인 추가
paragon0107 8d70a4a
feat: ScheduleAlarm 스케줄러및 클라우드 어댑터 구현
paragon0107 8aa50c0
chore: 컨벤션 수정
paragon0107 0e68b63
chore: 스케줄 시간 반영
paragon0107 8278cce
chore: 컨벤션 수정
paragon0107 c6ff1de
chore: scheduleAlarmRepository 분리
paragon0107 b24530e
chore: scheduleAlarmService 수정
paragon0107 22d1f36
feat: cloudTask 설정 추가
paragon0107 d69152d
chore: 임시 pr
paragon0107 0827fcb
chore: 테스트용 코드 삭제
paragon0107 9bc0c48
chore: 클라우드 태스크 토큰 부분 추가
paragon0107 8e46197
feat: 파일 read 예외 처리
paragon0107 d0515ef
chore: 주석 수정
paragon0107 113c095
chore: 바디 부분에 시간 추가
paragon0107 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
src/main/java/com/official/memento/global/config/QueryDslConfig.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| package com.official.memento.global.config; | ||
|
|
||
| import com.querydsl.jpa.impl.JPAQueryFactory; | ||
| import jakarta.persistence.EntityManager; | ||
| import lombok.AllArgsConstructor; | ||
| import org.springframework.context.annotation.Bean; | ||
| import org.springframework.context.annotation.Configuration; | ||
|
|
||
| @Configuration | ||
| @AllArgsConstructor | ||
| public class QueryDslConfig { | ||
|
|
||
| private final EntityManager entityManager; | ||
|
|
||
| @Bean | ||
| public JPAQueryFactory jpaQueryFactory(final EntityManager entityManager) { | ||
| return new JPAQueryFactory(entityManager); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
src/main/java/com/official/memento/schedule/domain/ScheduleAlarmRepository.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| package com.official.memento.schedule.domain; | ||
|
|
||
| import com.official.memento.schedule.domain.entity.ScheduleAlarm; | ||
| import java.time.LocalDateTime; | ||
| import java.util.List; | ||
|
|
||
| public interface ScheduleAlarmRepository { | ||
| List<ScheduleAlarm> findSchedulesWithMemberInfoBetween(final LocalDateTime startTime, final LocalDateTime endTime); | ||
| } |
1 change: 1 addition & 0 deletions
1
src/main/java/com/official/memento/schedule/domain/ScheduleRepository.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
src/main/java/com/official/memento/schedule/domain/entity/ScheduleAlarm.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| package com.official.memento.schedule.domain.entity; | ||
|
|
||
| import lombok.AllArgsConstructor; | ||
| import lombok.Getter; | ||
|
|
||
| import java.time.LocalDateTime; | ||
|
|
||
| @AllArgsConstructor | ||
| @Getter | ||
| public class ScheduleAlarm { | ||
|
|
||
| private final Long scheduleId; | ||
| private final Long memberId; | ||
| private final String description; | ||
| private final LocalDateTime startDate; | ||
| private final LocalDateTime endDate; | ||
| private final int timeZoneOffset; | ||
|
|
||
| public static ScheduleAlarm of( | ||
| final Long scheduleId, | ||
| final Long memberId, | ||
| final String description, | ||
| final LocalDateTime startDate, | ||
| final LocalDateTime endDate, | ||
| final int timeZoneOffset | ||
| ) { | ||
| return new ScheduleAlarm( | ||
| scheduleId, | ||
| memberId, | ||
| description, | ||
| startDate, | ||
| endDate, | ||
| timeZoneOffset | ||
| ); | ||
| } | ||
| } |
32 changes: 32 additions & 0 deletions
32
...ain/java/com/official/memento/schedule/infrastructure/ScheduleAlarmRepositoryAdapter.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| package com.official.memento.schedule.infrastructure; | ||
|
|
||
| import com.official.memento.global.stereotype.Adapter; | ||
| import com.official.memento.schedule.domain.ScheduleAlarmRepository; | ||
| import com.official.memento.schedule.domain.entity.ScheduleAlarm; | ||
| import com.official.memento.schedule.infrastructure.persistence.ScheduleAlarmCustomRepository; | ||
| import com.official.memento.schedule.infrastructure.persistence.projection.ScheduleAlarmProjection; | ||
| import java.time.LocalDateTime; | ||
| import java.util.List; | ||
| import lombok.RequiredArgsConstructor; | ||
|
|
||
| @Adapter | ||
| @RequiredArgsConstructor | ||
| public class ScheduleAlarmRepositoryAdapter implements ScheduleAlarmRepository { | ||
|
|
||
| private final ScheduleAlarmCustomRepository scheduleAlarmCustomRepository; | ||
|
|
||
| @Override | ||
| public List<ScheduleAlarm> findSchedulesWithMemberInfoBetween(final LocalDateTime startTime, | ||
| final LocalDateTime endTime) { | ||
| List<ScheduleAlarmProjection> scheduleAlarmProjections = scheduleAlarmCustomRepository.findSchedulesWithMemberInfoBetween( | ||
| startTime, endTime); | ||
| return scheduleAlarmProjections.stream().map(scheduleEntity -> ScheduleAlarm.of( | ||
| scheduleEntity.scheduleId(), | ||
| scheduleEntity.memberId(), | ||
| scheduleEntity.description(), | ||
| scheduleEntity.startDate(), | ||
| scheduleEntity.endDate(), | ||
| scheduleEntity.timeZoneOffset() | ||
| )).toList(); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
...m/official/memento/schedule/infrastructure/persistence/ScheduleAlarmCustomRepository.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| package com.official.memento.schedule.infrastructure.persistence; | ||
|
|
||
| import com.official.memento.member.infrastructure.persistence.entity.QMemberPersonalInfoEntity; | ||
| import com.official.memento.schedule.infrastructure.persistence.projection.ScheduleAlarmProjection; | ||
| import com.querydsl.core.Tuple; | ||
| import com.querydsl.jpa.impl.JPAQueryFactory; | ||
| import java.time.LocalDateTime; | ||
| import java.util.List; | ||
| import java.util.stream.Collectors; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.stereotype.Repository; | ||
|
|
||
| @Repository | ||
| @RequiredArgsConstructor | ||
| public class ScheduleAlarmCustomRepository { | ||
|
|
||
| private final JPAQueryFactory queryFactory; | ||
| QScheduleEntity schedule = QScheduleEntity.scheduleEntity; | ||
| QMemberPersonalInfoEntity memberPersonalInfo = QMemberPersonalInfoEntity.memberPersonalInfoEntity; | ||
|
|
||
| public List<ScheduleAlarmProjection> findSchedulesWithMemberInfoBetween( | ||
| final LocalDateTime startDate, | ||
| final LocalDateTime endDate | ||
| ) { | ||
| List<Tuple> results = queryFactory | ||
| .select(schedule.id, schedule.memberId, schedule.description, schedule.startDate, schedule.endDate, memberPersonalInfo.timeZoneOffset) | ||
| .from(schedule) | ||
| .join(memberPersonalInfo).on(schedule.memberId.eq(memberPersonalInfo.memberId)) | ||
| .where(schedule.startDate.between(startDate, endDate)) | ||
| .fetch(); | ||
|
|
||
| return results.stream() | ||
| .map(tuple -> new ScheduleAlarmProjection( | ||
| tuple.get(schedule.id), | ||
| tuple.get(schedule.memberId), | ||
| tuple.get(schedule.description), | ||
| tuple.get(schedule.startDate), | ||
| tuple.get(schedule.endDate), | ||
| tuple.get(memberPersonalInfo.timeZoneOffset) | ||
| )) | ||
| .collect(Collectors.toList()); | ||
| } | ||
|
|
||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
...icial/memento/schedule/infrastructure/persistence/projection/ScheduleAlarmProjection.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| package com.official.memento.schedule.infrastructure.persistence.projection; | ||
|
|
||
| import java.time.LocalDateTime; | ||
| import java.time.LocalTime; | ||
|
|
||
| public record ScheduleAlarmProjection( | ||
| Long scheduleId, | ||
| Long memberId, | ||
| String description, | ||
| LocalDateTime startDate, | ||
| LocalDateTime endDate, | ||
| Integer timeZoneOffset | ||
| ) { | ||
| } |
37 changes: 37 additions & 0 deletions
37
src/main/java/com/official/memento/schedule/scheduler/scheduleAlarmScheduler.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| package com.official.memento.schedule.scheduler; | ||
|
|
||
| import com.official.memento.global.exception.ErrorCode; | ||
| import com.official.memento.global.exception.MementoException; | ||
| import com.official.memento.schedule.domain.entity.ScheduleAlarm; | ||
| import com.official.memento.schedule.service.CloudTaskAdapter; | ||
| import com.official.memento.schedule.service.usecase.ScheduleAlarmGetUseCase; | ||
|
|
||
| import java.time.LocalDateTime; | ||
| import java.time.ZoneId; | ||
| import java.util.List; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.scheduling.annotation.Scheduled; | ||
| import org.springframework.stereotype.Component; | ||
|
|
||
| @Component | ||
| @RequiredArgsConstructor | ||
| public class scheduleAlarmScheduler { | ||
|
|
||
| private final CloudTaskAdapter cloudTaskAdapter; | ||
|
|
||
| private final ScheduleAlarmGetUseCase scheduleAlarmGetUseCase; | ||
|
|
||
| @Scheduled(cron = "0 15 0 * * *", zone = "UTC") // 매일 UTC 기준 0시 15분 | ||
| public void setScheduleAlarm() { | ||
| LocalDateTime now = LocalDateTime.now(ZoneId.of("UTC")).plusMinutes(30); | ||
| LocalDateTime tomorrow = now.plusDays(1); | ||
| List<ScheduleAlarm> schedules = scheduleAlarmGetUseCase.getSchedulesBetween(now, tomorrow); | ||
| try{ | ||
| for (ScheduleAlarm schedule : schedules) { | ||
| cloudTaskAdapter.createScheduleAlarm(schedule); | ||
| } | ||
| } catch (Exception e) { | ||
| throw new MementoException(ErrorCode.INTERNAL_SERVER_ERROR); | ||
| } | ||
| } | ||
| } |
88 changes: 88 additions & 0 deletions
88
src/main/java/com/official/memento/schedule/service/CloudTaskAdapter.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,88 @@ | ||||||||||||||||
| package com.official.memento.schedule.service; | ||||||||||||||||
|
|
||||||||||||||||
| import com.google.api.gax.core.FixedCredentialsProvider; | ||||||||||||||||
| import com.google.auth.oauth2.GoogleCredentials; | ||||||||||||||||
| import com.google.cloud.tasks.v2.CloudTasksClient; | ||||||||||||||||
| import com.google.cloud.tasks.v2.CloudTasksSettings; | ||||||||||||||||
| import com.google.cloud.tasks.v2.HttpMethod; | ||||||||||||||||
| import com.google.cloud.tasks.v2.HttpRequest; | ||||||||||||||||
| import com.google.cloud.tasks.v2.QueueName; | ||||||||||||||||
| import com.google.cloud.tasks.v2.Task; | ||||||||||||||||
| import com.google.protobuf.ByteString; | ||||||||||||||||
| import com.google.protobuf.Timestamp; | ||||||||||||||||
| import com.official.memento.global.exception.ErrorCode; | ||||||||||||||||
| import com.official.memento.global.exception.MementoException; | ||||||||||||||||
| import com.official.memento.schedule.domain.entity.ScheduleAlarm; | ||||||||||||||||
| import java.io.FileInputStream; | ||||||||||||||||
| import java.io.IOException; | ||||||||||||||||
| import java.time.Instant; | ||||||||||||||||
| import java.time.LocalDateTime; | ||||||||||||||||
| import java.time.ZoneOffset; | ||||||||||||||||
|
|
||||||||||||||||
| import org.springframework.beans.factory.annotation.Value; | ||||||||||||||||
| import org.springframework.stereotype.Component; | ||||||||||||||||
|
|
||||||||||||||||
| @Component | ||||||||||||||||
| public class CloudTaskAdapter { | ||||||||||||||||
|
|
||||||||||||||||
| @Value("${GCP.PROJECT_ID}") | ||||||||||||||||
| private String projectId; | ||||||||||||||||
|
|
||||||||||||||||
| @Value("${GCP.LOCATION_ID}") | ||||||||||||||||
| private String locationId; | ||||||||||||||||
|
|
||||||||||||||||
| @Value("${GCP.QUEUE_ID}") | ||||||||||||||||
| private String queueId; | ||||||||||||||||
|
|
||||||||||||||||
| @Value("${GCP.TARGET_URL}") | ||||||||||||||||
| private String targetUrl; | ||||||||||||||||
|
|
||||||||||||||||
| @Value("${ADMIN.TOKEN_PREFIX}") | ||||||||||||||||
| private String AUTHORIZATION_HEADER_ADMIN_PREFIX; | ||||||||||||||||
|
|
||||||||||||||||
|
|
||||||||||||||||
| public void createScheduleAlarm(final ScheduleAlarm scheduleAlarm) throws IOException { | ||||||||||||||||
| GoogleCredentials credentials = GoogleCredentials.fromStream( | ||||||||||||||||
| new FileInputStream(System.getenv("GOOGLE_APPLICATION_CREDENTIALS") | ||||||||||||||||
| )); | ||||||||||||||||
|
Comment on lines
+45
to
+47
|
||||||||||||||||
| GoogleCredentials credentials = GoogleCredentials.fromStream( | |
| new FileInputStream(System.getenv("GOOGLE_APPLICATION_CREDENTIALS") | |
| )); | |
| GoogleCredentials credentials; | |
| try (FileInputStream fis = new FileInputStream(System.getenv("GOOGLE_APPLICATION_CREDENTIALS"))) { | |
| credentials = GoogleCredentials.fromStream(fis); | |
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
QueryDSL은 현재 OpenFeign에서 fork해서 계속 프로젝트 업데이트를 진행하고 있습니다~
https://github.com/OpenFeign/querydsl
해당 의존성을 사용하면 좋을 것 같아요.