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: 세션 불참자 결석 처리 스케쥴러 구현 #41

Merged
merged 2 commits into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@ import com.depromeet.makers.domain.usecase.UseCase
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.runApplication
import org.springframework.context.annotation.ComponentScan
import org.springframework.context.annotation.EnableAspectJAutoProxy
import org.springframework.context.annotation.FilterType
import org.springframework.scheduling.annotation.EnableScheduling

@EnableScheduling
@EnableAspectJAutoProxy
@SpringBootApplication
@ComponentScan(
includeFilters = [ComponentScan.Filter(
Expand Down
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}")
}
}
}
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
}
}
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() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

요거 약간 함수명이 조금 더 명확하게 (updateAbsenceMember 거나.. 약간 그런느낌..?) 이면 좋을 것 같아요

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@CChuYong 반영했습니다~ 스케쥴러 패키지 위치도 문제 없는지만 확인 해주세요!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

좋은 것 같슴다~!

val today = LocalDateTime.of(LocalDate.now(), LocalTime.MIDNIGHT)
updateAbsenceMember.execute(UpdateAbsenceMember.UpdateAbsenceMemberInput(today))
}
}