-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #100 from TeamMiso/feat/environment-scheduler
🔀 :: 환경 정보 스케쥴러 구현
- Loading branch information
Showing
4 changed files
with
55 additions
and
1 deletion.
There are no files selected for viewing
5 changes: 5 additions & 0 deletions
5
...ndreas311/miso/domain/environment/application/port/input/UpdateTodayEnvironmentUseCase.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,5 @@ | ||
package andreas311.miso.domain.environment.application.port.input | ||
|
||
interface UpdateTodayEnvironmentUseCase { | ||
fun execute() | ||
} |
15 changes: 15 additions & 0 deletions
15
...dreas311/miso/domain/environment/application/scheduler/UpdateTodayEnvironmentScheduler.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,15 @@ | ||
package andreas311.miso.domain.environment.application.scheduler | ||
|
||
import andreas311.miso.domain.environment.application.port.input.UpdateTodayEnvironmentUseCase | ||
import org.springframework.scheduling.annotation.Scheduled | ||
import org.springframework.stereotype.Component | ||
|
||
@Component | ||
class UpdateTodayEnvironmentScheduler( | ||
private val updateTodayEnvironmentUseCase: UpdateTodayEnvironmentUseCase | ||
) { | ||
@Scheduled(cron = "0 0 0 * * ?") | ||
fun updateTodayEnvironment() { | ||
updateTodayEnvironmentUseCase.execute() | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...n/andreas311/miso/domain/environment/application/service/UpdateTodayEnvironmentService.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,27 @@ | ||
package andreas311.miso.domain.environment.application.service | ||
|
||
import andreas311.miso.common.annotation.RollbackService | ||
import andreas311.miso.domain.environment.application.port.input.UpdateTodayEnvironmentUseCase | ||
import andreas311.miso.domain.environment.application.port.output.QueryEnvironmentPort | ||
import andreas311.miso.domain.environment.application.port.output.QueryTodayEnvironmentPort | ||
import andreas311.miso.domain.environment.domain.Environment | ||
|
||
@RollbackService | ||
class UpdateTodayEnvironmentService( | ||
private val queryEnvironmentPort: QueryEnvironmentPort, | ||
private val queryTodayEnvironmentPort: QueryTodayEnvironmentPort | ||
) : UpdateTodayEnvironmentUseCase { | ||
override fun execute() { | ||
val todayEnvironment = queryTodayEnvironmentPort.findOne() | ||
|
||
val environment = getRandomEnvironment(todayEnvironment.title) | ||
|
||
todayEnvironment.updateTodayEnvironment(environment) | ||
} | ||
|
||
private fun getRandomEnvironment(title: String): Environment { | ||
|
||
val environments = queryEnvironmentPort.findAll().filterNot { it.title == title } | ||
return environments.shuffled().first() | ||
} | ||
} |
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