Skip to content

Commit

Permalink
Merge branch 'main' into feat/#89_hunca
Browse files Browse the repository at this point in the history
  • Loading branch information
belljun3395 authored Jul 13, 2024
2 parents a4f9500 + 4457d39 commit 7dc958f
Show file tree
Hide file tree
Showing 13 changed files with 117 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/code-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ env:
EMAIL_PASSWORD: ${{ secrets.EMAIL_PASSWORD }}

jobs:
build:
code-ci:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/integration-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ env:
EMAIL_PASSWORD: ${{ secrets.EMAIL_PASSWORD }}

jobs:
build:
integration-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand Down
12 changes: 12 additions & 0 deletions .github/workflows/wip.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: WIP
on:
pull_request:
types: [opened, synchronize, reopened, edited]

jobs:
wip:
runs-on: ubuntu-latest
steps:
- uses: wip/action@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2 changes: 2 additions & 0 deletions api/src/main/kotlin/com/few/api/config/ApiConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.few.api.repo.config.ApiRepoConfig
import com.few.batch.config.BatchConfig
import com.few.storage.document.config.DocumentStorageConfig
import com.few.storage.image.config.ImageStorageConfig
import org.springframework.boot.context.properties.ConfigurationPropertiesScan
import org.springframework.context.annotation.ComponentScan
import org.springframework.context.annotation.Configuration
import org.springframework.context.annotation.Import
Expand All @@ -15,6 +16,7 @@ import org.springframework.web.servlet.config.annotation.EnableWebMvc
@Import(ApiRepoConfig::class, BatchConfig::class, ImageStorageConfig::class, DocumentStorageConfig::class)
@EnableWebMvc
@EnableAsync
@ConfigurationPropertiesScan(basePackages = [ApiConfig.BASE_PACKAGE])
class ApiConfig {
companion object {
const val BASE_PACKAGE = "com.few.api"
Expand Down
39 changes: 39 additions & 0 deletions api/src/main/kotlin/com/few/api/config/ApiThreadPoolConfig.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.few.api.config

import com.few.api.config.properties.ThreadPoolProperties
import org.apache.juli.logging.LogFactory
import org.springframework.boot.context.properties.ConfigurationProperties
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor

@Configuration
class ApiThreadPoolConfig {

private val log = LogFactory.getLog(ApiThreadPoolConfig::class.java)

companion object {
const val DISCORD_HOOK_EVENT_POOL = "discord-task-"
}

@Bean
@ConfigurationProperties(prefix = "discord.thread-pool")
fun disCordThreadPoolProperties(): ThreadPoolProperties {
return ThreadPoolProperties()
}

@Bean(DISCORD_HOOK_EVENT_POOL)
fun discordHookThreadPool() = ThreadPoolTaskExecutor().apply {
val properties = disCordThreadPoolProperties()
corePoolSize = properties.getCorePoolSize()
maxPoolSize = properties.getMaxPoolSize()
queueCapacity = properties.getQueueCapacity()
setWaitForTasksToCompleteOnShutdown(properties.getWaitForTasksToCompleteOnShutdown())
setAwaitTerminationSeconds(properties.getAwaitTerminationSeconds())
setThreadNamePrefix("discordHookThreadPool-")
setRejectedExecutionHandler { r, _ ->
log.warn("Discord Hook Event Task Rejected: $r")
}
initialize()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.few.api.config.properties

import com.few.api.exception.properties.NotSetPropertyException

data class ThreadPoolProperties(
var corePoolSize: Int? = null,
var maxPoolSize: Int? = null,
var queueCapacity: Int? = null,
var waitForTasksToCompleteOnShutdown: Boolean? = null,
var awaitTerminationSeconds: Int? = null
) {
fun getCorePoolSize(): Int {
return corePoolSize ?: throw NotSetPropertyException("core pool size")
}

fun getMaxPoolSize(): Int {
return maxPoolSize ?: throw NotSetPropertyException("max pool size")
}

fun getQueueCapacity(): Int {
return queueCapacity ?: throw NotSetPropertyException("queue capacity")
}

fun getWaitForTasksToCompleteOnShutdown(): Boolean {
return waitForTasksToCompleteOnShutdown ?: throw NotSetPropertyException("waitForTasksToCompleteOnShutdown")
}

fun getAwaitTerminationSeconds(): Int {
return awaitTerminationSeconds ?: throw NotSetPropertyException("awaitTerminationSeconds")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.few.api.domain.subscription.event

import com.few.api.client.subscription.SubscriptionClient
import com.few.api.client.subscription.dto.WorkbookSubscriptionArgs
import com.few.api.config.ApiThreadPoolConfig.Companion.DISCORD_HOOK_EVENT_POOL
import com.few.api.domain.subscription.event.dto.WorkbookSubscriptionEvent
import com.few.api.domain.subscription.service.WorkbookService
import com.few.api.domain.subscription.service.dto.ReadWorkbookTitleInDto
Expand All @@ -18,7 +19,7 @@ class WorkbookSubscriptionEventListener(
private val workbookService: WorkbookService
) {

@Async
@Async(value = DISCORD_HOOK_EVENT_POOL)
@EventListener
fun handleWorkbookSubscriptionEvent(event: WorkbookSubscriptionEvent) {
val title = ReadWorkbookTitleInDto(event.workbookId).let { dto ->
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package com.few.api.exception.properties

class NotSetPropertyException(property: String) : RuntimeException("$property is not set")
8 changes: 8 additions & 0 deletions api/src/main/resources/application-client-local.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,11 @@ client:

webhook:
discord: "localhost:8080/webhook/discord/unused"

discord:
thread-pool:
core-pool-size: 5
max-pool-size: 15
queue-capacity: 30
wait-for-tasks-to-complete-on-shutdown: true
await-termination-seconds: 60
8 changes: 8 additions & 0 deletions api/src/main/resources/application-client-prd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,11 @@ client:

webhook:
discord: ${WEBHOOK_DISCORD}

discord:
thread-pool:
core-pool-size: ${DISCORD_THREAD_POOL_CORE_POOL_SIZE:5}
max-pool-size: ${DISCORD_THREAD_POOL_MAX_POOL_SIZE:15}
queue-capacity: ${DISCORD_THREAD_POOL_QUEUE_CAPACITY:30}
wait-for-tasks-to-complete-on-shutdown: ${DISCORD_THREAD_POOL_WAIT_FOR_TASKS_TO_COMPLETE_ON_SHUTDOWN:true}
await-termination-seconds: ${DISCORD_THREAD_POOL_AWAIT_TERMINATION_SECONDS:60}
8 changes: 8 additions & 0 deletions api/src/test/resources/application-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,11 @@ client:

webhook:
discord: https://discord.com/api/webhooks/1234567890/abcdefg

discord:
thread-pool:
core-pool-size: 5
max-pool-size: 15
queue-capacity: 30
wait-for-tasks-to-complete-on-shutdown: true
await-termination-seconds: 60
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ class WorkBookSubscriberWriter(
/** 마지막 학습지를 받은 구독자들은 구독을 해지한다.*/
dslContext.update(subscriptionT)
.set(subscriptionT.DELETED_AT, LocalDateTime.now())
.set(subscriptionT.UNSUBS_OPINION, "receive.all")
.where(subscriptionT.MEMBER_ID.`in`(receiveLastDayMembers))
.and(subscriptionT.TARGET_WORKBOOK_ID.`in`(targetWorkBookIds))
.execute()
Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ plugins {
id("org.hidetake.swagger.generator") version DependencyVersion.SWAGGER_GENERATOR
}

java.sourceCompatibility = JavaVersion.VERSION_17
java.sourceCompatibility = JavaVersion.VERSION_18

allprojects {
group = "com.few"
Expand Down

0 comments on commit 7dc958f

Please sign in to comment.