-
Notifications
You must be signed in to change notification settings - Fork 2
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
feat: 미션 인증 및 완료 사진 업로드 단계 예외케이스 처리 #114
Merged
kdomo
merged 12 commits into
develop
from
feature/109-mission-record-image-upload-exception-case
Jan 10, 2024
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
5a4be9d
chore: RedisConfig에 RedisKeyValueAdapter.EnableKeyspaceEvents.ON_STAR…
kdomo f19ec44
feat: MissionRecordTTl, Repository 클래스 생성
kdomo 1255f44
chore: RedisExpireEvent 상수 생성
kdomo 13b07d2
feat: RedisExpireEventRedisMessageListener 생성
kdomo 88aa764
chore: RedisMessageListenerConfig 생성
kdomo 53455ed
feat: 미션 일지 생성 후 Redis에 TTL 저장
kdomo 13ab87a
fix: TTL 10분으로 설정
kdomo 68c8c9a
Merge branch 'develop' into feature/109-mission-record-image-upload-e…
kdomo 7b30a84
style: spotless
kdomo 657084e
Merge branch 'develop' into feature/109-mission-record-image-upload-e…
kdomo 9445128
refactor: EXPIRATION_TIME 상수 적용과 ttl 변수명 변경
kdomo 18b918d
Merge branch 'develop' into feature/109-mission-record-image-upload-e…
kdomo 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
6 changes: 6 additions & 0 deletions
6
src/main/java/com/depromeet/domain/missionRecord/dao/MissionRecordTTLRepository.java
This file contains 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,6 @@ | ||
package com.depromeet.domain.missionRecord.dao; | ||
|
||
import com.depromeet.domain.missionRecord.domain.MissionRecordTTL; | ||
import org.springframework.data.repository.CrudRepository; | ||
|
||
public interface MissionRecordTTLRepository extends CrudRepository<MissionRecordTTL, Long> {} |
26 changes: 26 additions & 0 deletions
26
src/main/java/com/depromeet/domain/missionRecord/domain/MissionRecordTTL.java
This file contains 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,26 @@ | ||
package com.depromeet.domain.missionRecord.domain; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.Builder; | ||
import lombok.NoArgsConstructor; | ||
import org.springframework.data.annotation.Id; | ||
import org.springframework.data.redis.core.RedisHash; | ||
import org.springframework.data.redis.core.TimeToLive; | ||
|
||
@RedisHash("MissionRecordTTL") | ||
@NoArgsConstructor(access = AccessLevel.PRIVATE) | ||
public class MissionRecordTTL { | ||
@Id private String key; | ||
|
||
@TimeToLive private Long timeToLive; | ||
|
||
@Builder(access = AccessLevel.PRIVATE) | ||
private MissionRecordTTL(String key, Long timeToLive) { | ||
this.key = key; | ||
this.timeToLive = timeToLive; | ||
} | ||
|
||
public static MissionRecordTTL createMissionRecordTTL(String key, Long timeToLive) { | ||
return MissionRecordTTL.builder().key(key).timeToLive(timeToLive).build(); | ||
} | ||
} |
This file contains 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
37 changes: 37 additions & 0 deletions
37
...java/com/depromeet/domain/missionRecord/service/RedisExpireEventRedisMessageListener.java
This file contains 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.depromeet.domain.missionRecord.service; | ||
|
||
import com.depromeet.domain.missionRecord.dao.MissionRecordRepository; | ||
import com.depromeet.global.common.constants.RedisExpireEventConstants; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.data.redis.connection.Message; | ||
import org.springframework.data.redis.connection.MessageListener; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Slf4j | ||
@Component | ||
@RequiredArgsConstructor | ||
public class RedisExpireEventRedisMessageListener implements MessageListener { | ||
private final MissionRecordRepository missionRecordRepository; | ||
|
||
@Override | ||
public void onMessage(Message message, byte[] pattern) { | ||
String patternStr = new String(pattern); | ||
log.info( | ||
"RedisExpireEventRedisMessageListener.onMessage : message = {}, pattern = {}", | ||
message.toString(), | ||
patternStr); | ||
if (!patternStr.equals(RedisExpireEventConstants.REDIS_EXPIRE_EVENT_PATTERN.getValue())) { | ||
return; | ||
} | ||
String event = message.toString().split(":")[1]; | ||
|
||
if (!event.startsWith( | ||
RedisExpireEventConstants.EXPIRE_EVENT_IMAGE_UPLOAD_TIME_END.getValue())) { | ||
return; | ||
} | ||
|
||
Long missionRecordId = Long.valueOf(event.split("_")[6]); | ||
missionRecordRepository.deleteById(missionRecordId); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/com/depromeet/global/common/constants/RedisExpireEventConstants.java
This file contains 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,12 @@ | ||
package com.depromeet.global.common.constants; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
public enum RedisExpireEventConstants { | ||
REDIS_EXPIRE_EVENT_PATTERN("__keyevent@*__:expired"), | ||
EXPIRE_EVENT_IMAGE_UPLOAD_TIME_END("EXPIRE_EVENT_IMAGE_UPLOAD_TIME_END_"); | ||
private final String value; | ||
} |
This file contains 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 |
---|---|---|
|
@@ -8,9 +8,11 @@ | |
import org.springframework.data.redis.connection.RedisStandaloneConfiguration; | ||
import org.springframework.data.redis.connection.lettuce.LettuceClientConfiguration; | ||
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory; | ||
import org.springframework.data.redis.core.RedisKeyValueAdapter; | ||
import org.springframework.data.redis.repository.configuration.EnableRedisRepositories; | ||
|
||
@EnableRedisRepositories | ||
@EnableRedisRepositories( | ||
enableKeyspaceEvents = RedisKeyValueAdapter.EnableKeyspaceEvents.ON_STARTUP) | ||
@Configuration | ||
Comment on lines
+14
to
16
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
@RequiredArgsConstructor | ||
public class RedisConfig { | ||
|
24 changes: 24 additions & 0 deletions
24
src/main/java/com/depromeet/infra/config/redis/RedisMessageListenerConfig.java
This file contains 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,24 @@ | ||
package com.depromeet.infra.config.redis; | ||
|
||
import com.depromeet.domain.missionRecord.service.RedisExpireEventRedisMessageListener; | ||
import com.depromeet.global.common.constants.RedisExpireEventConstants; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.data.redis.connection.RedisConnectionFactory; | ||
import org.springframework.data.redis.listener.PatternTopic; | ||
import org.springframework.data.redis.listener.RedisMessageListenerContainer; | ||
|
||
@Configuration | ||
public class RedisMessageListenerConfig { | ||
@Bean | ||
public RedisMessageListenerContainer redisMessageListenerContainer( | ||
RedisConnectionFactory redisConnectionFactory, | ||
RedisExpireEventRedisMessageListener redisExpireEventRedisMessageListener) { | ||
RedisMessageListenerContainer container = new RedisMessageListenerContainer(); | ||
container.setConnectionFactory(redisConnectionFactory); | ||
container.addMessageListener( | ||
redisExpireEventRedisMessageListener, | ||
new PatternTopic(RedisExpireEventConstants.REDIS_EXPIRE_EVENT_PATTERN.getValue())); | ||
return container; | ||
} | ||
} |
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.
onMessage의 역할이 어떻게 되는 지 알 수 있을까요??
그리고 만약 onMessage가 호출된 것은 미션이 만료된 경우에 호출된 것으로 보이고,
missionRecord 미션 내역을 지우는 방식인 거 같아용
그때 지우기로 했는지, 종료 미션으로 해서 duration_status의 FINISHED enum으로 관리하기로 했는 지,
얘기가 나온 기억이 있어서 제가 잘못 알고 있었나해용
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.
onMessage의 경우 정해진 패턴에 이벤트가 발생했을때 수신되는 부분입니다 (해당 PR에서는 Redis의 expire event만 받기 때문에
__keyevent@*__:expired
가 패턴으로 설정되어있음)해당 메서드 안에서는 패턴이
__keyevent@*__:expired
가 맞는지 검사합니다.(현재는
expired
이벤트만 사용하고 추 후 다른 이벤트가 있다면 수정필요)정해진 패턴과 정해진 형식이 맞다면 해당 Key를 통해 MissionRecordId를 받아와 삭제하게됩니다.
백엔드 내부적으로 이야기했을 때, 해당 부분은 따로 enum으로 관리하지는 않을 것 같아용
윤범님이 생각하시는 부분은 아마
미션 졸업
스펙에서 14일이 종료되었을 때FINISHED
로 다루자고 하는 내용이지 않나 싶네용ㅎㅎㅎ 자세한 내용은 24.01.02 회의록에 첨부되어있습니당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.
아하 그러네용 자세한 답변 감사합니다!