-
Notifications
You must be signed in to change notification settings - Fork 1
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: 세션 불참자 결석 처리 스케쥴러 구현 #41
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 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
35 changes: 35 additions & 0 deletions
35
src/main/kotlin/com/depromeet/makers/domain/usecase/UpdateAbsenceMember.kt
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,35 @@ | ||
package com.depromeet.makers.domain.usecase | ||
|
||
import com.depromeet.makers.domain.gateway.AttendanceGateway | ||
import com.depromeet.makers.domain.gateway.SessionGateway | ||
import com.depromeet.makers.domain.model.AttendanceStatus | ||
import com.depromeet.makers.util.logger | ||
import java.time.LocalDateTime | ||
|
||
class UpdateAbsenceMember( | ||
private val sessionGateway: SessionGateway, | ||
private val attendanceGateway: AttendanceGateway, | ||
) : UseCase<UpdateAbsenceMember.UpdateAbsenceMemberInput, Unit> { | ||
data class UpdateAbsenceMemberInput( | ||
val today: LocalDateTime, | ||
) | ||
|
||
override fun execute(input: UpdateAbsenceMemberInput) { | ||
val logger = logger() | ||
|
||
val session = sessionGateway.findByStartTimeBetween(input.today, input.today.plusDays(1)) | ||
if (session == null) { | ||
return | ||
} | ||
|
||
val attendances = attendanceGateway.findAllByGenerationAndWeek(session.generation, session.week) | ||
attendances | ||
.filter { | ||
it.attendanceStatus == AttendanceStatus.ATTENDANCE_ON_HOLD | ||
} | ||
.forEach { | ||
attendanceGateway.save(it.copy(attendanceStatus = AttendanceStatus.ABSENCE)) | ||
logger.info("memberId: ${it.member.memberId} has been changed to ${AttendanceStatus.ATTENDANCE}") | ||
} | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
src/main/kotlin/com/depromeet/makers/presentation/restapi/config/aspect/SchedulerLogger.kt
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.makers.presentation.restapi.config.aspect | ||
|
||
import com.depromeet.makers.util.logger | ||
import org.aspectj.lang.ProceedingJoinPoint | ||
import org.aspectj.lang.annotation.Around | ||
import org.aspectj.lang.annotation.Aspect | ||
import org.springframework.stereotype.Component | ||
|
||
@Aspect | ||
@Component | ||
class SchedulerLogger { | ||
val logger = logger() | ||
|
||
@Around("@annotation(org.springframework.scheduling.annotation.Scheduled)") | ||
fun logging(joinPoint: ProceedingJoinPoint): Any? { | ||
val start = System.currentTimeMillis() | ||
logger.info("Scheduler: ${joinPoint.target.javaClass.simpleName} start") | ||
|
||
val result = joinPoint.proceed() | ||
|
||
val end = System.currentTimeMillis() | ||
logger.info("Scheduler: ${joinPoint.target.javaClass.simpleName} end, duration: ${end - start}ms") | ||
|
||
return result | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/main/kotlin/com/depromeet/makers/scheduler/AbsentMemberScheduler.kt
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,20 @@ | ||
package com.depromeet.makers.scheduler | ||
|
||
import com.depromeet.makers.domain.usecase.UpdateAbsenceMember | ||
import org.springframework.scheduling.annotation.Scheduled | ||
import org.springframework.stereotype.Component | ||
import java.time.LocalDate | ||
import java.time.LocalDateTime | ||
import java.time.LocalTime | ||
|
||
@Component | ||
class AbsentMemberScheduler( | ||
private val updateAbsenceMember: UpdateAbsenceMember | ||
) { | ||
|
||
@Scheduled(cron = "0 0 20 ? * SAT") | ||
fun scheduling() { | ||
val today = LocalDateTime.of(LocalDate.now(), LocalTime.MIDNIGHT) | ||
updateAbsenceMember.execute(UpdateAbsenceMember.UpdateAbsenceMemberInput(today)) | ||
} | ||
} |
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.
요거 약간 함수명이 조금 더 명확하게 (updateAbsenceMember 거나.. 약간 그런느낌..?) 이면 좋을 것 같아요
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.
@CChuYong 반영했습니다~ 스케쥴러 패키지 위치도 문제 없는지만 확인 해주세요!
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.
좋은 것 같슴다~!