Skip to content
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/288] 매너평가 메시지에 timestamp 추가 및 스케줄러 실행 간격 변경 #290

Merged
merged 1 commit into from
Oct 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/main/java/com/gamegoo/scheduler/SchedulerService.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.gamegoo.scheduler;

import com.gamegoo.domain.chat.Chat;
import com.gamegoo.domain.matching.MatchingRecord;
import com.gamegoo.domain.matching.MatchingStatus;
import com.gamegoo.repository.matching.MatchingRecordRepository;
Expand Down Expand Up @@ -31,7 +32,7 @@ public class SchedulerService {
* 매칭 성공 1시간이 경과한 경우, 두 사용자에게 매너평가 시스템 메시지 전송
*/
@Transactional
@Scheduled(fixedRate = 1000 * 60) // 60초 주기로 실행
@Scheduled(fixedRate = 5 * 60 * 1000) // 5 * 60초 주기로 실행
public void mannerSystemMessageRun() {
// log.info("scheduler start");

Expand All @@ -47,15 +48,15 @@ public void mannerSystemMessageRun() {
).ifPresentOrElse(
chatroom -> {
// 시스템 메시지 생성 및 db 저장
chatCommandService.createAndSaveSystemChat(
Chat createdChat = chatCommandService.createAndSaveSystemChat(
chatroom, matchingRecord.getMember(), MANNER_SYSTEM_MESSAGE, null, 1);

// 매너 평가 메시지 전송 여부 업데이트
matchingRecord.updateMannerMessageSent(true);

// socket 서버에게 메시지 전송 API 요청
socketService.sendSystemMessage(matchingRecord.getMember().getId(),
chatroom.getUuid(), MANNER_SYSTEM_MESSAGE);
chatroom.getUuid(), MANNER_SYSTEM_MESSAGE, createdChat.getTimestamp());
},
() -> log.info("Chatroom not found, member ID: {}, target member ID: {}",
matchingRecord.getMember().getId(), matchingRecord.getTargetMember().getId()));
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/com/gamegoo/service/socket/SocketService.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,14 @@ public void joinSocketToChatroom(Long memberId, String chatroomUuid) {
}
}

public void sendSystemMessage(Long memberId, String chatroomUuid, String content) {
public void sendSystemMessage(Long memberId, String chatroomUuid, String content,
Long timestamp) {
String url = SOCKET_SERVER_URL + "/socket/sysmessage";
Map<String, Object> requestBody = new HashMap<>();
requestBody.put("memberId", memberId);
requestBody.put("chatroomUuid", chatroomUuid);
requestBody.put("content", content);
requestBody.put("timestamp", timestamp);

try {
ResponseEntity<String> response = restTemplate.postForEntity(url, requestBody,
Expand Down
Loading