Skip to content

Commit

Permalink
Merge pull request #17 from kw-notice/refactor/issue-13
Browse files Browse the repository at this point in the history
batch application component scan error and timeout logic refactoring
  • Loading branch information
Tianea2160 authored Apr 30, 2023
2 parents 8d87ca7 + f8f9d46 commit ec584df
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.google.firebase.messaging.AndroidConfig
import com.google.firebase.messaging.AndroidNotification
import com.google.firebase.messaging.FirebaseMessaging
import com.google.firebase.messaging.Message
import kotlinx.coroutines.withTimeout
import org.slf4j.LoggerFactory
import org.springframework.stereotype.Service

Expand All @@ -13,7 +14,7 @@ class AlarmService(
) {
private val logger = LoggerFactory.getLogger(AlarmService::class.java)

suspend fun sendMessage(title: String, body: String, topic: AlarmTopic) {
suspend fun sendMessage(title: String, body: String, topic: AlarmTopic) = withTimeout(2000L) {
val notification = AndroidNotification.builder()
.setChannelId("kw_dormitory_notice_id")
.setTitle(title)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,18 @@ package com.knet.dormitory.config

import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.web.reactive.function.client.ExchangeStrategies
import org.springframework.web.reactive.function.client.WebClient

@Configuration
class WebClientConfig {
@Bean
fun webClient():WebClient = WebClient.create()
fun webClient(): WebClient {
val exchangeStrategies = ExchangeStrategies.builder()
.codecs { configurer -> configurer.defaultCodecs().maxInMemorySize(-1) }
.build()
return WebClient.builder()
.exchangeStrategies(exchangeStrategies)
.build()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.knet.batch
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.runApplication

@SpringBootApplication(scanBasePackages = ["com.knet.dormitory"])
@SpringBootApplication(scanBasePackages = ["com.knet"])
class DormitoryBatchApplication

fun main(args: Array<String>) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class DormitorySchedulingConfig(
tasklet(jobRepository, transactionManager, monitoringTasklet)
}

@Scheduled(cron = "1 * * * * *")
@Scheduled(cron = "0/10 * * * * *")
fun dormScheduling() {
val param = JobParametersBuilder()
.addDate("date", Date())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class MonitoringTasklet(
noticeService.createNoticeAll(notices)
try {
runBlocking(Dispatchers.IO) {
withTimeout(2000L) {

val deferreds = mutableListOf<Deferred<Unit>>()
notices.forEach { notice ->
val deferred = async {
Expand All @@ -64,7 +64,7 @@ class MonitoringTasklet(
}
for (deferred in deferreds) deferred.await()
}
}

} catch (e: Exception) {
logger.error("send message error : ${e.message}")
}
Expand Down

This file was deleted.

This file was deleted.

0 comments on commit ec584df

Please sign in to comment.