-
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
Changes from 10 commits
5a4be9d
f19ec44
1255f44
13b07d2
88aa764
53455ed
13ab87a
68c8c9a
7b30a84
657084e
9445128
18b918d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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> {} |
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(); | ||
} | ||
} |
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); | ||
} | ||
Comment on lines
+18
to
+36
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. onMessage의 역할이 어떻게 되는 지 알 수 있을까요?? 그리고 만약 onMessage가 호출된 것은 미션이 만료된 경우에 호출된 것으로 보이고, 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. onMessage의 경우 정해진 패턴에 이벤트가 발생했을때 수신되는 부분입니다 (해당 PR에서는 Redis의 expire event만 받기 때문에 해당 메서드 안에서는 패턴이 정해진 패턴과 정해진 형식이 맞다면 해당 Key를 통해 MissionRecordId를 받아와 삭제하게됩니다. 백엔드 내부적으로 이야기했을 때, 해당 부분은 따로 enum으로 관리하지는 않을 것 같아용 윤범님이 생각하시는 부분은 아마 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. 아하 그러네용 자세한 답변 감사합니다! |
||
} |
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; | ||
} |
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 { | ||
|
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; | ||
} | ||
} |
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.
상수로 빼는게 좋을 것 같아요