-
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.
* feat: 필드명 추가 * feat: daily content 생성 및 삭제 로직 추가 * feat: 오늘의 리마인드 api 수정 * feat: 오늘의 리마인드 스케줄러 설정 * feat: 코드리뷰 반영 * feat: batch 서버 배포 테스트 * feat: 임시 설정 * feat: 랜덤 개수 선정 수정 * feat: 설정 원복 * chore: push branch 수정
- Loading branch information
Showing
24 changed files
with
299 additions
and
51 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,6 @@ name: batch deploy | |
on: | ||
push: | ||
branches: | ||
- feature/#58 | ||
- main | ||
- develop | ||
paths: | ||
|
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
55 changes: 55 additions & 0 deletions
55
adapters/in-batch/src/main/kotlin/com/pokit/remind/job/DailyContentConfig.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,55 @@ | ||
package com.pokit.remind.job | ||
|
||
import com.navercorp.spring.batch.plus.kotlin.configuration.BatchDsl | ||
import com.pokit.content.port.`in`.DailyContentUseCase | ||
import com.pokit.user.port.`in`.UserUseCase | ||
import org.springframework.batch.core.Job | ||
import org.springframework.batch.core.Step | ||
import org.springframework.batch.repeat.RepeatStatus | ||
import org.springframework.context.annotation.Bean | ||
import org.springframework.context.annotation.Configuration | ||
import org.springframework.transaction.PlatformTransactionManager | ||
|
||
@Configuration | ||
class DailyContentConfig( | ||
private val transactionManager: PlatformTransactionManager, | ||
private val dailyContentUseCase: DailyContentUseCase, | ||
private val userUseCase: UserUseCase, | ||
private val batch: BatchDsl, | ||
) { | ||
|
||
@Bean | ||
fun updateDailyContentJob(): Job = batch { | ||
job("updateDailyContentJob") { | ||
step(deleteAllStep()) { | ||
on("COMPLETED") { | ||
step(updateDailyContentStep()) | ||
} | ||
} | ||
} | ||
} | ||
|
||
@Bean | ||
fun deleteAllStep(): Step = batch { | ||
step("deleteAllStep") { | ||
tasklet({ _, _ -> | ||
dailyContentUseCase.deleteAll() | ||
RepeatStatus.FINISHED | ||
}, transactionManager) | ||
} | ||
} | ||
|
||
@Bean | ||
fun updateDailyContentStep(): Step = batch { | ||
step("updateDailyContentStep") { | ||
tasklet({ _, _ -> | ||
val userIds: List<Long> = userUseCase.fetchAllUserId() | ||
|
||
for (userId in userIds) { | ||
dailyContentUseCase.registerDailyContent(userId) | ||
} | ||
RepeatStatus.FINISHED | ||
}, transactionManager) | ||
} | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
adapters/in-batch/src/main/kotlin/com/pokit/remind/scheduler/DailyContentUpdateScheduler.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,31 @@ | ||
package com.pokit.remind.scheduler | ||
|
||
import io.github.oshai.kotlinlogging.KotlinLogging | ||
import org.springframework.batch.core.Job | ||
import org.springframework.batch.core.JobParametersBuilder | ||
import org.springframework.batch.core.launch.JobLauncher | ||
import org.springframework.scheduling.annotation.Scheduled | ||
import org.springframework.stereotype.Component | ||
|
||
@Component | ||
class DailyContentUpdateScheduler( | ||
private val jobLauncher: JobLauncher, | ||
private val updateDailyContent: Job, | ||
) { | ||
private val logger = KotlinLogging.logger { } | ||
|
||
companion object { | ||
private const val 매일_자정 = "0 0 0 * * *" | ||
} | ||
|
||
@Scheduled(cron = 매일_자정) | ||
fun updateDailyContent() { | ||
val jobParameters = JobParametersBuilder() | ||
.addLong("run.id", System.currentTimeMillis()) | ||
.toJobParameters() | ||
|
||
logger.info { "[CONTENT BATCH] start daily content update job" } | ||
jobLauncher.run(updateDailyContent, jobParameters) | ||
logger.info { "[CONTENT BATCH] end daily content update job" } | ||
} | ||
} |
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
4 changes: 3 additions & 1 deletion
4
adapters/in-web/src/main/kotlin/com/pokit/content/dto/response/RemindContentResponse.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
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
44 changes: 44 additions & 0 deletions
44
...persistence/src/main/kotlin/com/pokit/out/persistence/content/impl/DailyContentAdapter.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,44 @@ | ||
package com.pokit.out.persistence.content.impl | ||
|
||
import com.pokit.content.dto.response.RemindContentResult | ||
import com.pokit.content.port.out.DailyContentPort | ||
import com.pokit.out.persistence.category.persist.QCategoryEntity.categoryEntity | ||
import com.pokit.out.persistence.content.persist.DailyContentEntity | ||
import com.pokit.out.persistence.content.persist.DailyContentRepository | ||
import com.pokit.out.persistence.content.persist.QContentEntity.contentEntity | ||
import com.pokit.out.persistence.content.persist.toDomain | ||
import org.springframework.stereotype.Component | ||
|
||
@Component | ||
class DailyContentAdapter( | ||
private val dailyContentRepository: DailyContentRepository, | ||
) : DailyContentPort { | ||
override fun fetchContentIdsByUserId(userId: Long) = | ||
dailyContentRepository.getContentIdsByUserId(userId) | ||
|
||
override fun loadByUserId(userId: Long): List<RemindContentResult> { | ||
val contentEntityList = dailyContentRepository.getDailyContentsByUserId(userId) | ||
|
||
return contentEntityList.map { | ||
RemindContentResult.of( | ||
it[contentEntity]!!.toDomain(), | ||
it[categoryEntity.name]!!, | ||
) | ||
} | ||
} | ||
|
||
override fun persist(userId: Long, ids: List<Long>) { | ||
val dailyContentEntities = ids.map { contentId -> | ||
DailyContentEntity( | ||
userId = userId, | ||
contentId = contentId | ||
) | ||
} | ||
|
||
dailyContentRepository.saveAll(dailyContentEntities) | ||
} | ||
|
||
override fun deleteAll() = | ||
dailyContentRepository.deleteAll() | ||
|
||
} |
16 changes: 16 additions & 0 deletions
16
...rsistence/src/main/kotlin/com/pokit/out/persistence/content/persist/DailyContentEntity.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,16 @@ | ||
package com.pokit.out.persistence.content.persist | ||
|
||
import jakarta.persistence.* | ||
|
||
@Table(name = "DAILY_CONTENT") | ||
@Entity | ||
class DailyContentEntity( | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
@Column(name = "id") | ||
val id: Long = 0L, | ||
|
||
val userId: Long, | ||
|
||
val contentId: Long, | ||
) |
8 changes: 8 additions & 0 deletions
8
...c/main/kotlin/com/pokit/out/persistence/content/persist/DailyContentQuerydslRepository.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,8 @@ | ||
package com.pokit.out.persistence.content.persist | ||
|
||
import com.querydsl.core.Tuple | ||
|
||
interface DailyContentQuerydslRepository { | ||
fun getDailyContentsByUserId(userId: Long): List<Tuple> | ||
fun getContentIdsByUserId(userId: Long): List<Long> | ||
} |
33 changes: 33 additions & 0 deletions
33
...in/kotlin/com/pokit/out/persistence/content/persist/DailyContentQuerydslRepositoryImpl.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,33 @@ | ||
package com.pokit.out.persistence.content.persist | ||
|
||
import com.pokit.out.persistence.category.persist.QCategoryEntity.categoryEntity | ||
import com.pokit.out.persistence.content.persist.QContentEntity.contentEntity | ||
import com.pokit.out.persistence.content.persist.QDailyContentEntity.dailyContentEntity | ||
import com.querydsl.core.Tuple | ||
import com.querydsl.jpa.impl.JPAQueryFactory | ||
import org.springframework.stereotype.Repository | ||
|
||
@Repository | ||
class DailyContentQuerydslRepositoryImpl( | ||
private val queryFactory: JPAQueryFactory | ||
) : DailyContentQuerydslRepository { | ||
override fun getDailyContentsByUserId(userId: Long): MutableList<Tuple> = | ||
queryFactory.select(contentEntity, categoryEntity.name) | ||
.from(contentEntity) | ||
.join(dailyContentEntity).on(contentEntity.id.eq(dailyContentEntity.contentId)) | ||
.join(categoryEntity).on(contentEntity.categoryId.eq(categoryEntity.id)) | ||
.where(dailyContentEntity.userId.eq(userId)) | ||
.fetch() | ||
|
||
override fun getContentIdsByUserId(userId: Long): List<Long> = | ||
queryFactory | ||
.select(contentEntity.id) | ||
.from(contentEntity) | ||
.join(categoryEntity).on(contentEntity.categoryId.eq(categoryEntity.id)) | ||
.where( | ||
categoryEntity.userId.eq(userId) | ||
.and(categoryEntity.deleted.eq(false)) | ||
.and(contentEntity.deleted.eq(false)) | ||
) | ||
.fetch() | ||
} |
5 changes: 5 additions & 0 deletions
5
...tence/src/main/kotlin/com/pokit/out/persistence/content/persist/DailyContentRepository.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 com.pokit.out.persistence.content.persist | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository | ||
|
||
interface DailyContentRepository: JpaRepository<DailyContentEntity, Long>, DailyContentQuerydslRepository |
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
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
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
9 changes: 9 additions & 0 deletions
9
application/src/main/kotlin/com/pokit/content/port/in/DailyContentUseCase.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,9 @@ | ||
package com.pokit.content.port.`in` | ||
|
||
import com.pokit.content.dto.response.RemindContentResult | ||
|
||
interface DailyContentUseCase { | ||
fun registerDailyContent(userId: Long) | ||
fun deleteAll() | ||
fun getDailyContents(userId: Long): List<RemindContentResult> | ||
} |
10 changes: 10 additions & 0 deletions
10
application/src/main/kotlin/com/pokit/content/port/out/DailyContentPort.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,10 @@ | ||
package com.pokit.content.port.out | ||
|
||
import com.pokit.content.dto.response.RemindContentResult | ||
|
||
interface DailyContentPort { | ||
fun loadByUserId(userId: Long): List<RemindContentResult> | ||
fun fetchContentIdsByUserId(userId: Long): List<Long> | ||
fun persist(userId: Long, ids: List<Long>) | ||
fun deleteAll() | ||
} |
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
Oops, something went wrong.