-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
굿~
- Loading branch information
Showing
3 changed files
with
104 additions
and
0 deletions.
There are no files selected for viewing
52 changes: 52 additions & 0 deletions
52
gg-pingpong-api/src/main/java/gg/party/api/admin/room/service/RoomStatusService.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,52 @@ | ||
package gg.party.api.admin.room.service; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.List; | ||
|
||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import gg.data.party.Room; | ||
import gg.data.party.type.RoomType; | ||
import gg.repo.party.RoomRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Slf4j | ||
public class RoomStatusService { | ||
private final RoomRepository roomRepository; | ||
|
||
/** | ||
* 방 FINISH 변경 스케쥴러 | ||
* 시작한 방(START) 2시간후에 FINISH로 변경 | ||
*/ | ||
@Transactional | ||
public void finishStartedRooms() { | ||
LocalDateTime twoHoursAgo = LocalDateTime.now().minusHours(2); | ||
List<Room> startedRooms = roomRepository.findByStatus(RoomType.START, null); | ||
for (Room room : startedRooms) { | ||
room.updateRoomStatus(RoomType.FINISH); | ||
roomRepository.save(room); | ||
log.info("Room {} status updated to FINISH", room.getId()); | ||
} | ||
} | ||
|
||
/** | ||
* 방 FAIL 변경 스케쥴러 | ||
* due date 지났는데 시작 안했으면 FAIL로 변경 | ||
*/ | ||
@Transactional | ||
public void failOpenedRooms() { | ||
LocalDateTime now = LocalDateTime.now(); | ||
List<Room> openRooms = roomRepository.findByStatus(RoomType.OPEN, null); | ||
for (Room room : openRooms) { | ||
if (room.getDueDate().isBefore(now)) { | ||
room.updateRoomStatus(RoomType.FAIL); | ||
roomRepository.save(room); | ||
log.info("Room {} status updated to FAIL", room.getId()); | ||
} | ||
} | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
gg-pingpong-api/src/main/java/gg/party/api/admin/scheduler/FailRoomScheduler.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 gg.party.api.admin.scheduler; | ||
|
||
import org.springframework.stereotype.Component; | ||
|
||
import gg.party.api.admin.room.service.RoomStatusService; | ||
import gg.pingpong.api.global.scheduler.AbstractScheduler; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
@Slf4j | ||
@Component | ||
public class FailRoomScheduler extends AbstractScheduler { | ||
private final RoomStatusService roomStatusService; | ||
|
||
public FailRoomScheduler(RoomStatusService roomStatusService) { | ||
this.roomStatusService = roomStatusService; | ||
this.setCron("0 0/5 * * * *"); | ||
} | ||
|
||
@Override | ||
public Runnable runnable() { | ||
return () -> { | ||
log.info("FailOpenedRoomsScheduler start"); | ||
roomStatusService.failOpenedRooms(); | ||
}; | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
gg-pingpong-api/src/main/java/gg/party/api/admin/scheduler/FinishRoomScheduler.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 gg.party.api.admin.scheduler; | ||
|
||
import org.springframework.stereotype.Component; | ||
|
||
import gg.party.api.admin.room.service.RoomStatusService; | ||
import gg.pingpong.api.global.scheduler.AbstractScheduler; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
@Slf4j | ||
@Component | ||
public class FinishRoomScheduler extends AbstractScheduler { | ||
private final RoomStatusService roomStatusService; | ||
|
||
public FinishRoomScheduler(RoomStatusService roomStatusService) { | ||
this.roomStatusService = roomStatusService; | ||
this.setCron("0 0/5 * * * *"); // Example: Run every 5 minutes | ||
} | ||
|
||
@Override | ||
public Runnable runnable() { | ||
return () -> { | ||
log.info("FinishStartedRoomsScheduler start"); | ||
roomStatusService.finishStartedRooms(); | ||
}; | ||
} | ||
} |