Skip to content

Commit

Permalink
feat: 세션 불참자 결석 처리 스케쥴러 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
ddingmin committed May 19, 2024
1 parent f733972 commit 60b1b30
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 0 deletions.
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,26 @@
package com.depromeet.makers.scheduler

import com.depromeet.makers.domain.usecase.UpdateAbsenceMember
import com.depromeet.makers.util.logger
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 logger = logger()
logger.info("Scheduler start")

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

logger.info("Scheduler end")
}
}

0 comments on commit 60b1b30

Please sign in to comment.